Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

array question about print

Featured Replies

Alright sorry for opening posts lately but book is very unclear this time.

 

$zin1[1]="The first thing";

$zin1[2]=" The second thing";

 

print ($zin1).'<br>';

 

This is the curent code offcourse enclosed in php.

 

Now we all know we must do print_r($zin1); in order to see the array.

However mine book does the code like above but if I do that I get an error.

The <br> code won't print when you do print_f so it won't work.

 

What's the best solution in this kind of array?

I know there are different kinds of ways to produce arrays but this is for the study:).

Not really understanding what you are asking to be honest

Best thing I can suggest is to use

echo '<pre>' . print_r($zin1, true) . '</pre>';

That should format it nicely for you

Not really understanding what you are asking to be honest

Best thing I can suggest is to use

echo '<pre>' . print_r($zin1, true) . '</pre>';

That should format it nicely for you

 

 

Unless I'm mistaken echo "<pre>".print_r(array())."</pre>"; would syntax error? You can't echo a print_r() can you? Unless you set the second param to true?

  • Author

That will indeed giving a syntax error.

I'm not sure but from what I currently know, shouldn't <pre></pre> together in 1 single quote and not like that.

Anyway, I can print it out by using a for each that came later in the chapter.

Maby it was a pre-example to foreach.

 

anyway it's solved:)

Unless I'm mistaken echo "<pre>".print_r(array())."</pre>"; would syntax error? You can't echo a print_r() can you? Unless you set the second param to true?

 

Huh? Neither of them would give a syntax error, but not using the second param would mean 1 gets output as well as the array

And as for echoing a print_r, yes you need the true param set (which it is in my example) :unsure:

That will indeed giving a syntax error.

I'm not sure but from what I currently know, shouldn't <pre></pre> together in 1 single quote and not like that.

Anyway, I can print it out by using a for each that came later in the chapter.

Maby it was a pre-example to foreach.

 

anyway it's solved:)

 

Basically my example above prints out the array using print_r but it puts it within <pre> </pre> tags, so that its preformatted. echoing out print_r will not give a syntax error, since it has a return type (and even if it didn't it would return null)

Basically my example above prints out the array using print_r but it puts it within <pre> </pre> tags, so that its preformatted. echoing out print_r will not give a syntax error, since it has a return type (and even if it didn't it would return null)

 

Apologies, I gave an opinion without testing, but we're both kind of wrong:

 

<?php

error_reporting(E_ALL);

$args = array('a','b','c');

echo "<pre>".print_r($args)."</pre>";

?>

 

Outputs

 

Array
(
   [0] => a
   [1] => b
   [2] => c
)
<pre>1</pre>

 

 

<?php

error_reporting(E_ALL);

$args = array('a','b','c');

echo "<pre>".print_r($args,true)."</pre>";

?>

 

Outputs

 

<pre>Array
(
   [0] => a
   [1] => b
   [2] => c
)
</pre>

Sorry but I'm confused now. The second example you gave is exactly what I was saying would be output by my original code and what I was expecting to show, as it formats it nicely in a browser. I don't even know where the whole no second param came from

Sorry but I'm confused now. The second example you gave is exactly what I was saying would be output by my original code and what I was expecting to show, as it formats it nicely in a browser. I don't even know where the whole no second param came from

 

 

Hahahaha, I'm such a dick. I wrote all that **** out for no reason. I completely missed your 2nd param. Apologies and +1#s coming your way :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.