Jump to content


Photo

arrays


  • Please log in to reply
4 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 21 April 2006 - 09:06 PM

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.
<!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>
<?php
var_dump($test1);
?>
</pre>
<pre>
<?php
var_dump($test2);
?>
</pre>
<pre>
<?php
var_dump($test3);
?>
</pre>


</body>
</html>

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.
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"
}


------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 gizmola

gizmola
  • Administrators
  • Advanced Member
  • 4,664 posts
  • LocationLos Angeles, CA USA

Posted 21 April 2006 - 10:17 PM

If your question is about var_dump() you can make your own prettier output using a foreach loop. See foreach in the php manual.

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 21 April 2006 - 10:23 PM

thanks

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 21 April 2006 - 11:28 PM

... or if you just want to see contents of arrays without the type and size info, use print_r() instead of var_dump().

echo '<pre>',
       print_r($test1, true),
       print_r($test2, true),
       print_r($test3, true),
       '</pre>';

-->
Array
(
)
Array
(
    [a] => Dave
    [b] => Jim
    [c] => Walton
    [d] => Peter
)
Array
(
    [a] => Jessy
    [b] => Mark
    [c] => Tim
    [d] => Fairy
)

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 21 April 2006 - 11:30 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users