Welcome visitor
* Login
* Register
It is currently January 17th, 2019, 12:30 am
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Server Side » PHP



Post new topic Reply to topic  [ 7 posts ] 
Author Message
  array inside an array question
PostPosted: March 25th, 2009, 1:22 am 
User avatar

Posts: 63
i have these 2 arrays,

$name = array ("Albertson, George", "Anderson, John", "Brown, Phillip");
$code = array ("alg1", "anj1", "brp1");

and i want to put them inside a third array, lets call it users, how can i do it?

i have seen the php.net, but is too confusing for me, thanks for your understanding.


Top
 Profile  
 
  Re: array inside an array question
PostPosted: March 25th, 2009, 1:37 am 
User avatar

Posts: 112
$users = array (
    "name"    => array("Albertson, George", "Anderson, John", "Brown, Phillip"),
    "code"    => array("alg1", "anj1", "brp1")
);
now "name" and "code" are "key" values inside the "users" array. also you can do
$name = array ("Albertson, George", "Anderson, John", "Brown, Phillip");
$code = array ("alg1", "anj1", "brp1");
$users = array ($name,$code);
in this case have in mind that the "key"s inside "users" arent gonna be "name" and "code" but 0 and 1. is this what you asked about?


Top
 Profile  
 
  Re: array inside an array question
PostPosted: March 25th, 2009, 1:40 am 
User avatar

Posts: 63
ok, now, how can i get the values from the array-name now that they are inside users?


Top
 Profile  
 
  Re: array inside an array question
PostPosted: March 25th, 2009, 1:43 am 
User avatar

Posts: 112
im taking the array where "name" is the "key"
foreach ($users["name"] as $value){echo $value;}


Top
 Profile  
 
  Re: array inside an array question
PostPosted: March 25th, 2009, 1:45 am 
User avatar

Posts: 63
thanks


Top
 Profile  
 
  Re: array inside an array question
PostPosted: March 26th, 2009, 12:39 pm 

Posts: 1
Hai,

You can better use array_merge.
Here is the sample code.

<?php

$first_array = array(1, 2, 3, 4, 5, 6);
$second_array = array(10, 9, 7, 3, 5);

$new_array = array_merge($first_array, $second_array);
print_r($new_array);
?>


/*

OUTPUT

Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 10
[7] => 9
[8] => 7
[9] => 3
[10] => 5
)

*/


Top
 Profile  
 
  Re: array inside an array question
PostPosted: March 26th, 2009, 1:31 pm 
User avatar

Posts: 63
THANKS elan4u !!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

FORUMS » Server Side » PHP


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron