Discussion:
regarding print_r()
Sachin Raut
2013-11-10 05:09:03 UTC
Permalink
Hello,


I am trying to print following array using print_r(), but it appends number
"1" to the output. Can someone pls tell me what is the issue here or is
there any setting i need to do in PHP.


Thanks

Sachin Raut


<?php

$a[]="Paris";

$a[]="London";

echo print_r($a);

?>


Output :

Array ( [0] => Paris [1] => London ) 1
Sachin Raut
2013-11-10 05:24:04 UTC
Permalink
Issue resolved. I didn't notice that i was passing print_r() function to
echo. Silly mistake.

Thanks
Sachin Raut


On Sun, Nov 10, 2013 at 10:39 AM, Sachin Raut <***@gmail.com>wrote:

> Hello,
>
>
> I am trying to print following array using print_r(), but it appends
> number "1" to the output. Can someone pls tell me what is the issue here or
> is there any setting i need to do in PHP.
>
>
> Thanks
>
> Sachin Raut
>
>
> <?php
>
> $a[]="Paris";
>
> $a[]="London";
>
> echo print_r($a);
>
> ?>
>
>
> Output :
>
> Array ( [0] => Paris [1] => London ) 1
>
Camilo Sperberg
2013-11-10 09:09:39 UTC
Permalink
On 10 nov. 2013, at 06:24, Sachin Raut <***@gmail.com> wrote:

> Issue resolved. I didn't notice that i was passing print_r() function to
> echo. Silly mistake.
>
> Thanks
> Sachin Raut
>
>
> On Sun, Nov 10, 2013 at 10:39 AM, Sachin Raut <***@gmail.com>wrote:
>
>> Hello,
>>
>>
>> I am trying to print following array using print_r(), but it appends
>> number "1" to the output. Can someone pls tell me what is the issue here or
>> is there any setting i need to do in PHP.
>>
>>
>> Thanks
>>
>> Sachin Raut
>>
>>
>> <?php
>>
>> $a[]="Paris";
>>
>> $a[]="London";
>>
>> echo print_r($a);
>>
>> ?>
>>
>>
>> Output :
>>
>> Array ( [0] => Paris [1] => London ) 1
>>

I think everyone on this list has made that same mistake once.

Just as a sidenote, you can pass true as second parameter to have print_r return the contents instead of printing them directly. It comes in very handy in case you need to escape characters before printing or manipulate the string before you want to print.

Greetings.

Met vriendelijke groet,
Camilo Sperberg

----------------
W: http://unreal4u.com
T: http://twitter.com/unreal4u


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sachin Raut
2013-11-10 13:26:24 UTC
Permalink
Thank you Mr.Sperberg for telling about 2nd parameter. Really appreciate
your help.

Thanks
Sachin Raut


On Sun, Nov 10, 2013 at 2:39 PM, Camilo Sperberg <***@gmail.com> wrote:

>
> On 10 nov. 2013, at 06:24, Sachin Raut <***@gmail.com> wrote:
>
> > Issue resolved. I didn't notice that i was passing print_r() function to
> > echo. Silly mistake.
> >
> > Thanks
> > Sachin Raut
> >
> >
> > On Sun, Nov 10, 2013 at 10:39 AM, Sachin Raut <***@gmail.com
> >wrote:
> >
> >> Hello,
> >>
> >>
> >> I am trying to print following array using print_r(), but it appends
> >> number "1" to the output. Can someone pls tell me what is the issue
> here or
> >> is there any setting i need to do in PHP.
> >>
> >>
> >> Thanks
> >>
> >> Sachin Raut
> >>
> >>
> >> <?php
> >>
> >> $a[]="Paris";
> >>
> >> $a[]="London";
> >>
> >> echo print_r($a);
> >>
> >> ?>
> >>
> >>
> >> Output :
> >>
> >> Array ( [0] => Paris [1] => London ) 1
> >>
>
> I think everyone on this list has made that same mistake once.
>
> Just as a sidenote, you can pass true as second parameter to have print_r
> return the contents instead of printing them directly. It comes in very
> handy in case you need to escape characters before printing or manipulate
> the string before you want to print.
>
> Greetings.
>
> Met vriendelijke groet,
> Camilo Sperberg
>
> ----------------
> W: http://unreal4u.com
> T: http://twitter.com/unreal4u
>
>
Ken Robinson
2013-11-10 14:15:46 UTC
Permalink
A nice application of the second parameter is to get the output of
print_r formatted on your web page:

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

much easier to read...

Ken

At 08:26 AM 11/10/2013, Sachin Raut wrote:
>Thank you Mr.Sperberg for telling about 2nd parameter. Really appreciate
>your help.
>
>Thanks
>Sachin Raut
>
>
>On Sun, Nov 10, 2013 at 2:39 PM, Camilo Sperberg <***@gmail.com> wrote:
>
> >
> > On 10 nov. 2013, at 06:24, Sachin Raut <***@gmail.com> wrote:
> >
> > > Issue resolved. I didn't notice that i was passing print_r() function to
> > > echo. Silly mistake.
> > >
> > > Thanks
> > > Sachin Raut
> > >
> > >
> > > On Sun, Nov 10, 2013 at 10:39 AM, Sachin Raut <***@gmail.com
> > >wrote:
> > >
> > >> Hello,
> > >>
> > >>
> > >> I am trying to print following array using print_r(), but it appends
> > >> number "1" to the output. Can someone pls tell me what is the issue
> > here or
> > >> is there any setting i need to do in PHP.
> > >>
> > >>
> > >> Thanks
> > >>
> > >> Sachin Raut
> > >>
> > >>
> > >> <?php
> > >>
> > >> $a[]="Paris";
> > >>
> > >> $a[]="London";
> > >>
> > >> echo print_r($a);
> > >>
> > >> ?>
> > >>
> > >>
> > >> Output :
> > >>
> > >> Array ( [0] => Paris [1] => London ) 1
> > >>
> >
> > I think everyone on this list has made that same mistake once.
> >
> > Just as a sidenote, you can pass true as second parameter to have print_r
> > return the contents instead of printing them directly. It comes in very
> > handy in case you need to escape characters before printing or manipulate
> > the string before you want to print.
> >
> > Greetings.
> >
> > Met vriendelijke groet,
> > Camilo Sperberg
> >
> > ----------------
> > W: http://unreal4u.com
> > T: http://twitter.com/unreal4u
> >
> >


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
George Wilson
2013-11-12 18:35:03 UTC
Permalink
That is insanely awesome!

Thanks for passing that along.


On Tue, Nov 12, 2013 at 10:17 AM, Phred White <***@planetphred.com>wrote:

> My fave:
>
> echo '<textarea> . print_r($a,true) . '</textarea>';
>
> - print_r's indents etc. maintained (as in <pre>)
> - default textarea is small and consistent size, doesn't disrupt layout
> even for massive arrays
> - you can resize at will (at least in Safari)
> - you can have multiples for complex problem solving and view them next to
> each other!
>
> On Nov 10, 2013, at 8:15 AM, Ken Robinson wrote:
>
> > A nice application of the second parameter is to get the output of
> print_r formatted on your web page:
> >
> > echo '<pre>' . print_r($ary, true) . '</pre>';
> >
> > much easier to read...
> >
> > Ken
> >
> > At 08:26 AM 11/10/2013, Sachin Raut wrote:
> >> Thank you Mr.Sperberg for telling about 2nd parameter. Really appreciate
> >> your help.
> >>
> >> Thanks
> >> Sachin Raut
> >>
> >>
> >> On Sun, Nov 10, 2013 at 2:39 PM, Camilo Sperberg <***@gmail.com>
> wrote:
> >>
> >> >
> >> > On 10 nov. 2013, at 06:24, Sachin Raut <***@gmail.com>
> wrote:
> >> >
> >> > > Issue resolved. I didn't notice that i was passing print_r()
> function to
> >> > > echo. Silly mistake.
> >> > >
> >> > > Thanks
> >> > > Sachin Raut
> >> > >
> >> > >
> >> > > On Sun, Nov 10, 2013 at 10:39 AM, Sachin Raut <
> ***@gmail.com
> >> > >wrote:
> >> > >
> >> > >> Hello,
> >> > >>
> >> > >>
> >> > >> I am trying to print following array using print_r(), but it
> appends
> >> > >> number "1" to the output. Can someone pls tell me what is the issue
> >> > here or
> >> > >> is there any setting i need to do in PHP.
> >> > >>
> >> > >>
> >> > >> Thanks
> >> > >>
> >> > >> Sachin Raut
> >> > >>
> >> > >>
> >> > >> <?php
> >> > >>
> >> > >> $a[]="Paris";
> >> > >>
> >> > >> $a[]="London";
> >> > >>
> >> > >> echo print_r($a);
> >> > >>
> >> > >> ?>
> >> > >>
> >> > >>
> >> > >> Output :
> >> > >>
> >> > >> Array ( [0] => Paris [1] => London ) 1
> >> > >>
> >> >
> >> > I think everyone on this list has made that same mistake once.
> >> >
> >> > Just as a sidenote, you can pass true as second parameter to have
> print_r
> >> > return the contents instead of printing them directly. It comes in
> very
> >> > handy in case you need to escape characters before printing or
> manipulate
> >> > the string before you want to print.
> >> >
> >> > Greetings.
> >> >
> >> > Met vriendelijke groet,
> >> > Camilo Sperberg
> >> >
> >> > ----------------
> >> > W: http://unreal4u.com
> >> > T: http://twitter.com/unreal4u
> >> >
> >> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Phred White
2013-11-12 18:17:41 UTC
Permalink
My fave:

echo '<textarea> . print_r($a,true) . '</textarea>';

- print_r's indents etc. maintained (as in <pre>)
- default textarea is small and consistent size, doesn't disrupt layout even for massive arrays
- you can resize at will (at least in Safari)
- you can have multiples for complex problem solving and view them next to each other!

On Nov 10, 2013, at 8:15 AM, Ken Robinson wrote:

> A nice application of the second parameter is to get the output of print_r formatted on your web page:
>
> echo '<pre>' . print_r($ary, true) . '</pre>';
>
> much easier to read...
>
> Ken
>
> At 08:26 AM 11/10/2013, Sachin Raut wrote:
>> Thank you Mr.Sperberg for telling about 2nd parameter. Really appreciate
>> your help.
>>
>> Thanks
>> Sachin Raut
>>
>>
>> On Sun, Nov 10, 2013 at 2:39 PM, Camilo Sperberg <***@gmail.com> wrote:
>>
>> >
>> > On 10 nov. 2013, at 06:24, Sachin Raut <***@gmail.com> wrote:
>> >
>> > > Issue resolved. I didn't notice that i was passing print_r() function to
>> > > echo. Silly mistake.
>> > >
>> > > Thanks
>> > > Sachin Raut
>> > >
>> > >
>> > > On Sun, Nov 10, 2013 at 10:39 AM, Sachin Raut <***@gmail.com
>> > >wrote:
>> > >
>> > >> Hello,
>> > >>
>> > >>
>> > >> I am trying to print following array using print_r(), but it appends
>> > >> number "1" to the output. Can someone pls tell me what is the issue
>> > here or
>> > >> is there any setting i need to do in PHP.
>> > >>
>> > >>
>> > >> Thanks
>> > >>
>> > >> Sachin Raut
>> > >>
>> > >>
>> > >> <?php
>> > >>
>> > >> $a[]="Paris";
>> > >>
>> > >> $a[]="London";
>> > >>
>> > >> echo print_r($a);
>> > >>
>> > >> ?>
>> > >>
>> > >>
>> > >> Output :
>> > >>
>> > >> Array ( [0] => Paris [1] => London ) 1
>> > >>
>> >
>> > I think everyone on this list has made that same mistake once.
>> >
>> > Just as a sidenote, you can pass true as second parameter to have print_r
>> > return the contents instead of printing them directly. It comes in very
>> > handy in case you need to escape characters before printing or manipulate
>> > the string before you want to print.
>> >
>> > Greetings.
>> >
>> > Met vriendelijke groet,
>> > Camilo Sperberg
>> >
>> > ----------------
>> > W: http://unreal4u.com
>> > T: http://twitter.com/unreal4u
>> >
>> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Shawn McKenzie
2013-11-12 19:17:11 UTC
Permalink
FWIW, I use var_export() since it is valid PHP code and can be copy/pasted
etc.


On Sat, Nov 9, 2013 at 11:09 PM, Sachin Raut <***@gmail.com> wrote:

> Hello,
>
>
> I am trying to print following array using print_r(), but it appends number
> "1" to the output. Can someone pls tell me what is the issue here or is
> there any setting i need to do in PHP.
>
>
> Thanks
>
> Sachin Raut
>
>
> <?php
>
> $a[]="Paris";
>
> $a[]="London";
>
> echo print_r($a);
>
> ?>
>
>
> Output :
>
> Array ( [0] => Paris [1] => London ) 1
>
Tamara Temple
2013-11-12 23:00:36 UTC
Permalink
+ for var_export()!
+ for textarea!


On Nov 12, 2013, at 1:17 PM, Shawn McKenzie <***@mckenzies.net> wrote:

> FWIW, I use var_export() since it is valid PHP code and can be copy/pasted
> etc.
>
>
> On Sat, Nov 9, 2013 at 11:09 PM, Sachin Raut <***@gmail.com> wrote:
>
>> Hello,
>>
>>
>> I am trying to print following array using print_r(), but it appends number
>> "1" to the output. Can someone pls tell me what is the issue here or is
>> there any setting i need to do in PHP.
>>
>>
>> Thanks
>>
>> Sachin Raut
>>
>>
>> <?php
>>
>> $a[]="Paris";
>>
>> $a[]="London";
>>
>> echo print_r($a);
>>
>> ?>
>>
>>
>> Output :
>>
>> Array ( [0] => Paris [1] => London ) 1
>>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sachin Raut
2013-11-13 03:26:39 UTC
Permalink
Wow...didn't know about textarea & var_export(). Really awesome.

thanks
Sachin Raut


On Wed, Nov 13, 2013 at 4:30 AM, Tamara Temple <***@gmail.com>wrote:

> + for var_export()!
> + for textarea!
>
>
> On Nov 12, 2013, at 1:17 PM, Shawn McKenzie <***@mckenzies.net> wrote:
>
> > FWIW, I use var_export() since it is valid PHP code and can be
> copy/pasted
> > etc.
> >
> >
> > On Sat, Nov 9, 2013 at 11:09 PM, Sachin Raut <***@gmail.com>
> wrote:
> >
> >> Hello,
> >>
> >>
> >> I am trying to print following array using print_r(), but it appends
> number
> >> "1" to the output. Can someone pls tell me what is the issue here or is
> >> there any setting i need to do in PHP.
> >>
> >>
> >> Thanks
> >>
> >> Sachin Raut
> >>
> >>
> >> <?php
> >>
> >> $a[]="Paris";
> >>
> >> $a[]="London";
> >>
> >> echo print_r($a);
> >>
> >> ?>
> >>
> >>
> >> Output :
> >>
> >> Array ( [0] => Paris [1] => London ) 1
> >>
>
>
Continue reading on narkive:
Loading...