/    Sign up×
Community /Pin to ProfileBookmark

read array inside array

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.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 13.2005 — [code=php]
<?php
echo "<pre>";
print_r($array_name);
echo "</pre>n";
?>
[/code]
Copy linkTweet thisAlerts:
@acemoauthorDec 13.2005 — that gives this output:
<i>
</i>Array
(
[0] =&gt; Acemo
[1] =&gt; Array
)

tnx anyways
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 13.2005 — yes, it means the array is 2 dimensional

the first contains 2 elements: the string 'Acemo' and and array (which seems empty)
Copy linkTweet thisAlerts:
@acemoauthorDec 13.2005 — 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?
[code=php]
<?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("&#160;" => " ");
$addchar = strtr($addchar, $trans);
array_push($character, $addchar);
}
echo "<pre>";
print_r($character);
echo "</pre>n";
}
?>
[/code]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 13.2005 — what is the $trans array?
Copy linkTweet thisAlerts:
@acemoauthorDec 13.2005 — the second one is for changing the space code ( & # 1 6 0 ; ) into a normal space.
Copy linkTweet thisAlerts:
@NogDogDec 14.2005 — When you do [b]$trans = array('key' => 'value');[/b] 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: [b]$trans['key'] = 'value';[/b] and that will append that new element to the array.
Copy linkTweet thisAlerts:
@acemoauthorDec 14.2005 — actually, its ok for the first $trans to get overwriten.
Copy linkTweet thisAlerts:
@acemoauthorDec 14.2005 — besides the $trans, nothing looks wrong? :S
×

Success!

Help @acemo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...