Page 1 of 1
Array Problem
Posted: Thu Sep 06, 2007 12:42 am
by Mute
Hi,
Can someone tell me how to mimic the following using array_push?
Code: Select all
$replacements = array(
"test" => array("!*EMAIL*!" => "email@email.com"),
"dummy" => array("!*EMAIL*!" => "dude@dude.com"),
"qwerty" => array("!*EMAIL*!" => "test@test.com")
);
Cheers!
Posted: Thu Sep 06, 2007 1:11 am
by s.dot
You can't mimic the creation of an array with array_push(). array_push() simply adds elements to an array.
EDIT| I suppose you could create an empty array, and array push your 3 arrays into it.
Posted: Thu Sep 06, 2007 1:13 am
by Mute
That's what I'm trying to do. Basically, I've got a loop with all the details and need to push these into an array but can't seem to get it to work with the 2-d array.
Posted: Thu Sep 06, 2007 1:28 am
by s.dot
Code: Select all
$replacements = array();
$test = array ('blabhalbhalba');
array_push($replacements, $test);
Posted: Thu Sep 06, 2007 1:35 am
by Mute
I know how to do an array_push. I just can't do it with the 2-d array.
I'm trying this but it's not working.
Code: Select all
$replacements = array();
array_push($replacements, $test);
array_push($stack, "matt@advergamer.co.uk" => array("!*EMAIL*!" => "matt@advergamer.co.uk"));
Posted: Thu Sep 06, 2007 1:40 am
by s.dot
Mute wrote:I know how to do an array_push. I just can't do it with the 2-d array.
I'm trying this but it's not working.
Code: Select all
$replacements = array();
array_push($replacements, $test);
array_push($stack, "matt@advergamer.co.uk" => array("!*EMAIL*!" => "matt@advergamer.co.uk"));
Where's $stack coming from?
the second argument in the second array push is not a valid argument. it's a string and an array. wrap it in array()
Posted: Thu Sep 06, 2007 1:48 am
by Mute
scottayy wrote:Mute wrote:I know how to do an array_push. I just can't do it with the 2-d array.
I'm trying this but it's not working.
Code: Select all
$replacements = array();
array_push($replacements, $test);
array_push($stack, "matt@advergamer.co.uk" => array("!*EMAIL*!" => "matt@advergamer.co.uk"));
Where's $stack coming from?
the second argument in the second array push is not a valid argument. it's a string and an array. wrap it in array()
Sorry, long day and my last post made no sense. Let me start again (and thanks for the help).
Code: Select all
$replacements = array();
array_push($replacements , "matt@advergamer.co.uk" => array("!*EMAIL*!" => "matt@advergamer.co.uk"));
That's what I'm trying and it's not working. You say that I need to wrap the whole statement in array(). Like thus?
Code: Select all
$replacements = array();
array_push($replacements , array("matt@advergamer.co.uk" => array("!*EMAIL*!" => "matt@advergamer.co.uk")));
That works. Kind of but it's not quite right. If I print out the array I get....
Code: Select all
Array ( [0] => Array ( [matt@advergamer.co.uk] => Array ( [!*EMAIL*!] => matt@advergamer.co.uk ) ) )
I need to have....
Code: Select all
Array ( [matt@advergamer.co.uk] => Array ( [!*EMAIL*!] => matt@advergamer.co.uk ) )
Thanks once again mate.
Posted: Thu Sep 06, 2007 1:54 am
by s.dot
Ah. I guess I didn't understand your question fully. Apologies.
Code: Select all
$replacements['matt@advergamer.co.uk'] = array('!*EMAIL*!" => "matt@advergamer.co.uk");
Should do the trick.
Posted: Thu Sep 06, 2007 2:02 am
by Mute
Beautiful! We got there eventually.
Looking at that I'm an idiot, problem was so simple but I was trying to complicate it by using array_push.
Thanks buddy, life saver!