Ninjakreborn Posted April 21, 2006 Share Posted April 21, 2006 I need to figure something out, I was messing around with some code in arrays, and I set up something here to make this more readable, is there an easier way to do this.below is my code and below that is my output into the browser.[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>php test page</title></head><body><?php$array1 = array("a"=>"Dave", "b"=>"Jim", "c"=>"Walton", "d"=>"Peter");$array2 = array("a"=>"Jessy", "b"=>"Mark", "c"=>"Tim", "d"=>"Fairy");$test1 = array_intersect($array1, $array2);$test2 = array_diff($array1, $array2);$test3 = array_merge($array1, $array2);?><pre><?phpvar_dump($test1);?></pre><pre><?phpvar_dump($test2);?></pre><pre><?phpvar_dump($test3);?></pre></body></html>[/code]And below here is what it outputs into the browser., but is there an easier way to write this code, writing it standard just drops it in a bunch of heavily unreadable lines.[code]array(0) {}array(4) { ["a"]=> string(4) "Dave" ["b"]=> string(3) "Jim" ["c"]=> string(6) "Walton" ["d"]=> string(5) "Peter"}array(4) { ["a"]=> string(5) "Jessy" ["b"]=> string(4) "Mark" ["c"]=> string(3) "Tim" ["d"]=> string(5) "Fairy"}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8083-arrays/ Share on other sites More sharing options...
gizmola Posted April 21, 2006 Share Posted April 21, 2006 If your question is about var_dump() you can make your own prettier output using a foreach loop. See foreach in the php manual. Quote Link to comment https://forums.phpfreaks.com/topic/8083-arrays/#findComment-29476 Share on other sites More sharing options...
Ninjakreborn Posted April 21, 2006 Author Share Posted April 21, 2006 thanks Quote Link to comment https://forums.phpfreaks.com/topic/8083-arrays/#findComment-29480 Share on other sites More sharing options...
Barand Posted April 21, 2006 Share Posted April 21, 2006 ... or if you just want to see contents of arrays without the type and size info, use print_r() instead of var_dump().[code]echo '<pre>', print_r($test1, true), print_r($test2, true), print_r($test3, true), '</pre>';[/code]--> [code]Array()Array( [a] => Dave [b] => Jim [c] => Walton [d] => Peter)Array( [a] => Jessy [b] => Mark [c] => Tim [d] => Fairy)[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8083-arrays/#findComment-29499 Share on other sites More sharing options...
Ninjakreborn Posted April 21, 2006 Author Share Posted April 21, 2006 ah so that is what print_r was for, I want to experiment with it some on non-array variables later and see what I can come up with too. Quote Link to comment https://forums.phpfreaks.com/topic/8083-arrays/#findComment-29500 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.