Reply to Re: [PHP] Array: If i'm in the child array then how I tell the parent's key name..

Your name:

Reply:


Posted by Ing. Josuι Aranda on 10/01/05 17:52

Scott, I hope this code help you:

[PHP CODE]
/*
* Author:
* Josue Aranda <josue@ingeniodigital.com.mx>
*/

// This set an $arr
$arr = array(
'ABC' => array(
'DEF' => 'Data'
)
);

print_r($arr);

/*
* Will OutPut:
*
* Array
* (
* [ABC] => Array
* (
* [DEF] => Data
* )
*
* )
*/

echo $arr['ABC']['DEF']; // Will Output "Data"

$level = 0;

foreach ($arr as $key => $value){
$level++;
echo " Level: ".$level." Key: ".$key; // Will output "Level: 1 Key: ABC"
foreach ($value as $subKey => $subValue){
$level++;
echo " Level: ".$level." Key: ".$subKey; // Will OutPut "Level: 2 Key: DEF"
$level--;
}
$level--;
}
[/PHP CODE]

are you trying to make some kind of tree?



On 9/30/05, Scott Fletcher <scott@abcoa.com> wrote:
> Suppose that I'm in a child array and I wanna know how do I tell what key is
> the parent's level, one level up...
>
> For example,
>
> --snip--
> $arr['ABC']['DEF'];
> --snip--
>
> Let's say the child is "DEF" then the key name one level up would be "ABC".
> How do I determine the one level up?
>
> Thanks...
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--


________________________

JOSUE ARANDA>>>
http://josuearanda.com

[Back to original 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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация