Welcome Guest, Not a member yet? Register   Sign In
Array helper :: element()
#1

[eluser]Bondie[/eluser]
Say my array is something similar too:

Code:
$array = array('code' => array('html' => '<code></code>', 'bbcode' => '[code][\/code]'),
'php' => array('html' => '<span class="php"></span>', 'bbcode' => '[php][/php]')
);

obviously thats not going to work as its not valid blah blah, my question is using element() can i get an element of an element...?
I can obviously get the first element using:
Code:
$php = element('php',$array');

How would i get the second element??? :\
Code:
$bbcode = element('bbcode',$php)

would that work??

From the manual example usage:
Code:
$array = array('color' => 'red', 'shape' => 'round', 'size' => '');

// returns "red"
echo element('color', $array);

// returns NULL
echo element('size', $array, NULL);
#2

[eluser]bretticus[/eluser]
Good theory. Have you actually tried it?

Basically, I think the array helper is pretty useless (except maybe the other function.)

One thing about PHP (and many other languages) is that traversing an array is pretty easy. What's wrong with:

Code:
if ( isset($array['php']['bbcode']) ){
  $bbcode = $array['php']['bbcode'];
}
#3

[eluser]Bondie[/eluser]
Never really thought of doing it that way, simply because I barely use arrays, and only really use them where i need to, so this could prove easier than element Smile thank you very much.
#4

[eluser]bretticus[/eluser]
[quote author="Bondie" date="1254432041"]Never really thought of doing it that way, simply because I barely use arrays, and only really use them where i need to, so this could prove easier than element Smile thank you very much.[/quote]

You are very welcome. Arrays in PHP is like the proverbial swiss army knife of the PHP developer. I have seldom seen a PHP script, in fact, where I didn't see an array used somewhere. The standard for passing data to a view is an associative array, for example. I suspect you will be getting more familiar with arrays. :-)
#5

[eluser]Bondie[/eluser]
Okay, ignore this post, now fixed this problem ^_^




Theme © iAndrew 2016 - Forum software by © MyBB