Appending Array
Moderator: General Moderators
Appending Array
Hey,
So if I have double leyer array how can I add extra data from the erray with the same structure?
Ex: server[0][ip_addr] = 1.1.1.1
and I want say add another server server with Ip so nex record would be server[1][ip_addr] =2.2.2.2
How to?
Thanks!
So if I have double leyer array how can I add extra data from the erray with the same structure?
Ex: server[0][ip_addr] = 1.1.1.1
and I want say add another server server with Ip so nex record would be server[1][ip_addr] =2.2.2.2
How to?
Thanks!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
$server[]['ip_addr'] = '2.2.2.2';
Remove the numerical indice
Remove the numerical indice
Last edited by John Cartwright on Fri Apr 07, 2006 7:09 pm, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$foo = array(
'ip_addr' => '2.2.2.2',
'port' => 88,
'ttl' => 50
);
$server[] = $foo;- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
It does go "I++" notice the last line, that adds the newly created array to the end of $server, another array (from your previous posts in this thread.)alexus wrote:feyd, but still thats a regular assigning of stuks to an array, but I have double layer, and I need first layer to go I++ and assign evertthing else "mannually"..... eee im getting overloaded
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
$foo = array(
'ip_addr' => '2.2.2.2',
'port' => 88,
'ttl' => 50
);
#some more processing...
$foo['someOther'] = $blah;
$foo['someOther2'] = $blah2;
#when processing is done then assign to parent array
$server[] = $foo;oh
this is now used to append, hm ok let me try that, I always thought thta would preplace the content with the new one
Code: Select all
$server[] = $foo;