July 11, 201115 yr 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:).
July 11, 201115 yr 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
July 12, 201115 yr 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?
July 12, 201115 yr 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:)
July 12, 201115 yr 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)
July 12, 201115 yr 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)
July 12, 201115 yr 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>
July 12, 201115 yr 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
July 12, 201115 yr 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