You are here: Nested Array refs? « PHP Language « IT news, forums, messages
Nested Array refs?

Posted by DC on 07/07/05 19:19

Having some trouble creating an array of array-refs. (I think thats what its
called)

Below is the script that i am writing, followed by the output. So far this
is fine.
But what I would like to be able to do is specifically call up a string like
so

$filedef[1]['host'] - just dont know the syntax im looking for...
so in the script i change change "echo "File Definition $i: -> $item\n";" to
echo "File Definition $i: Backup host = $item[$i]['host'] \n";

hope that clearly describes what im trying to do




#!/usr/bin/php -q
<?


$filedef[0] = array('file' => '.cshrc', 'filedir' => '/home/user1', 'host'
=> 'backhost1', 'backdir' => '/tmp');
$filedef[1] = array('file' => '.profile', 'filedir' => '/home/user2, 'host'
=> 'backhost2', 'backdir' => '/somewhere');


for ($i=0;$i<count($filedef);$i++){


foreach ($filedef[$i] as $item) {
echo "File Definition $i: -> $item\n";
}
echo "\n";
}


?>
-------------------------------------------------
File Definition 0: -> .cshrc
File Definition 0: -> /home/user1
File Definition 0: -> backhost1
File Definition 0: -> /tmp

File Definition 1: -> .profile
File Definition 1: -> /home/user2
File Definition 1: -> backhost2
File Definition 1: -> /somewhere

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация