Click to See Complete Forum and Search --> : read array inside array


acemo
12-13-2005, 05:00 PM
I made a script, and its output is an array inside an array.
I would like to know what the output exactly contains.

Anyone could make me a script that does the following?
Read an array, including the array inside the first array.
*either outputs to screen.
*either outputs to text file.

NogDog
12-13-2005, 05:05 PM
<?php
echo "<pre>";
print_r($array_name);
echo "</pre>\n";
?>

acemo
12-13-2005, 05:11 PM
that gives this output:

Array
(
[0] => Acemo
[1] => Array
)

tnx anyways

LiLcRaZyFuZzY
12-13-2005, 05:20 PM
yes, it means the array is 2 dimensional
the first contains 2 elements: the string 'Acemo' and and array (which seems empty)

acemo
12-13-2005, 05:33 PM
ok.. then my script aint working..
The following script was supposed to check all character names on the page ($file), then putting these all in the variable $character, could anyone take a look, what i did wrong here?

<?php
$guild = "Order of Banor";
$guild = ucfirst("$guild");
$trans = array(" " => "+");
$guild = strtr($guild, $trans);
echo "$guild <br>";
$file = "http://www.tibia.com/community/?subtopic=guilds&page=view&GuildName=$guild";
$text = file_get_contents($file) or die("Unable to read file.");
$character[0] = "Acemo";
if(preg_match_all('/(?<=name=)[^<]+(?=">)/i', $text, $matches)){
foreach( $matches as $nr => $name){
$addchar = ucfirst($matches[$nr]);
$trans = array(" " => " ");
$addchar = strtr($addchar, $trans);
array_push($character, $addchar);
}
echo "<pre>";
print_r($character);
echo "</pre>\n";
}
?>

LiLcRaZyFuZzY
12-13-2005, 05:38 PM
what is the $trans array?

acemo
12-13-2005, 05:49 PM
the second one is for changing the space code ( & # 1 6 0 ; ) into a normal space.

NogDog
12-13-2005, 06:21 PM
When you do $trans = array('key' => 'value'); that creates a new array (effectively overwriting any existing array of the same name). So your second assignment to $trans is getting rid of the first. Instead, do: $trans['key'] = 'value'; and that will append that new element to the array.

acemo
12-14-2005, 12:21 AM
actually, its ok for the first $trans to get overwriten.

acemo
12-14-2005, 12:37 PM
besides the $trans, nothing looks wrong? :S