var-dump

Making PHP var_dump() values display one line per value

天涯浪子 提交于 2019-11-29 22:02:10
When I echo var_dump($_variable), I get one long, wrapping line with all varable's and values like ["kt_login_user"]=> string(8) "teacher1" ["kt_login_id"]=> string(3) "973" ["kt_campusID"]=> string(4) "9088" ["kt_positionID"]=> string(1) "5" Is there a way I can make each value display on its own line for ease of reading? Something like this: ["kt_login_user"]=> string(8) "teacher1" ["kt_login_id"]=> string(3) "973" ["kt_campusID"]=> string(4) "9088" ["kt_positionID"]=> string(1) "5" phirschybar Yes, try wrapping it with <pre> , e.g.: echo '<pre>' , var_dump($variable) , '</pre>'; I usually

Unexpected observation: var_dump() of an array is flagging referenced elements… since when?

混江龙づ霸主 提交于 2019-11-29 19:43:02
问题 I've just been running some simple debug tests against arrays, and noticed that when I do a var_dump() of an array, the output is flagging any element in the array that is referenced by another variable. As a simple experiment, I ran the following code: $array = range(1,4); var_dump($array); echo '<br />'; foreach($array as &$value) { } var_dump($array); echo '<br />'; $value2 = &$array[1]; var_dump($array); echo '<br />'; which gives the following output: array(4) { [0]=> int(1) [1]=> int(2)

Why would var_dump return a bigger value than the string length?

烂漫一生 提交于 2019-11-29 14:51:37
I am working on getting some song lyrics using an API, and converting the lyrics string into an array of words. I am getting some unusual behaviors in preg_replace function. When I did some debugging using var_dump, I see that var_dump returns a value of 10 for the string "you", which tells me that there might be something wrong. After that preg_replace acts weirdly. This is my code: $source = get_chart_lyrics_data("madonna","frozen"); $pieces = explode("\n", $source); $lyrics = array(); for($i=0;$i<count($pieces);$i++){ if($i>10){ $words = explode(" ",$pieces[$i]); foreach($words as $_word){

Why does var_dump show filename and line number?

给你一囗甜甜゛ 提交于 2019-11-29 10:32:25
Just recently var_dump() in PHP (currently using 5.6.23) started to print out the filename as well as the line number before actually dumping my variable. I'm not aware of any major changes on the server, so I was wondering why this happens, also there's nothing to be found on the web or in the PHP-documentation ( var_dump() ) The strange behaviour also happens when using the command line: > php -r 'var_dump("lol");' Command line code:1: string(3) "lol" While I'm just used to "string(3) "lol"" being printed. This is not a showstopper but broke a couple of my unit-tests where I needed to

How do I properly use print_r or var_dump?

↘锁芯ラ 提交于 2019-11-29 09:35:57
问题 I use the following snippet quite often when I am debugging: echo "<pre>" . var_dump($var) . "</pre>"; And I find I usually get a nice readable output. But sometimes I just don't. I'm particularly vexed at the moment by this example: <?php $username='xxxxxx'; $password='xxxxxx'; $data_url='http://docs.tms.tribune.com/tech/tmsdatadirect/schedulesdirect/tvDataDelivery.wsdl'; $start=gmdate("Y-m-d\TH:i:s\Z",time()); $stop =gmdate("Y-m-d\TH:i:s\Z",time()+3600*24); $client = new SoapClient($data

Making PHP var_dump() values display one line per value

為{幸葍}努か 提交于 2019-11-28 17:18:45
问题 When I echo var_dump($_variable), I get one long, wrapping line with all varable's and values like ["kt_login_user"]=> string(8) "teacher1" ["kt_login_id"]=> string(3) "973" ["kt_campusID"]=> string(4) "9088" ["kt_positionID"]=> string(1) "5" Is there a way I can make each value display on its own line for ease of reading? Something like this: ["kt_login_user"]=> string(8) "teacher1" ["kt_login_id"]=> string(3) "973" ["kt_campusID"]=> string(4) "9088" ["kt_positionID"]=> string(1) "5" 回答1:

Why would var_dump return a bigger value than the string length?

元气小坏坏 提交于 2019-11-28 08:15:41
问题 I am working on getting some song lyrics using an API, and converting the lyrics string into an array of words. I am getting some unusual behaviors in preg_replace function. When I did some debugging using var_dump, I see that var_dump returns a value of 10 for the string "you", which tells me that there might be something wrong. After that preg_replace acts weirdly. This is my code: $source = get_chart_lyrics_data("madonna","frozen"); $pieces = explode("\n", $source); $lyrics = array(); for(

Why does var_dump show filename and line number?

拜拜、爱过 提交于 2019-11-28 03:38:48
问题 Just recently var_dump() in PHP (currently using 5.6.23) started to print out the filename as well as the line number before actually dumping my variable. I'm not aware of any major changes on the server, so I was wondering why this happens, also there's nothing to be found on the web or in the PHP-documentation (var_dump()) The strange behaviour also happens when using the command line: > php -r 'var_dump("lol");' Command line code:1: string(3) "lol" While I'm just used to "string(3) "lol""

Make var_dump look pretty

倾然丶 夕夏残阳落幕 提交于 2019-11-27 16:44:15
I have a simple $_GET[] query var set for showing testing data when pulling down queries from the DB. <?php if($_GET['test']): ?> <div id="test" style="padding: 24px; background: #fff; text-align: center;"> <table> <tr style="font-weight: bold;"><td>MLS</td></tr> <tr><td><?php echo KEY; ?></td></tr> <tr style="font-weight: bold;"><td>QUERY</td></tr> <tr><td><?php echo $data_q; ?></td></tr> <tr style="font-weight: bold;"><td>DATA</td></tr> <tr><td><?php var_dump($data); ?></td></tr> </table> </div> <?php endif; ?> When I do var_dump , as expected it's this big array string that is all smushed

What is the JavaScript equivalent of var_dump or print_r in PHP? [duplicate]

假如想象 提交于 2019-11-27 05:50:28
This question already has an answer here: Is there an equivalent for var_dump (PHP) in Javascript? 17 answers I would like to see the structure of object in JavaScript (for debugging). Is there anything similar to var_dump in PHP? Paolo Bergantino Most modern browsers have a console in their developer tools, useful for this sort of debugging. console.log(myvar); Then you will get a nicely mapped out interface of the object/whatever in the console. Check out the console documentation for more details. Most common way: console.log(object); However I must mention JSON.stringify which is useful to