Welcome to WebmasterWorld Guest from 54.196.244.45

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Replacing Values in Array

     
12:52 pm on Jan 20, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:July 17, 2006
posts:137
votes: 0


I have an array called $names that outputs like this:


Array
(
[1] => Array
(
[FULL_NAME] => Second, First
[LAST_NAME] => Second
[FIRST_NAME] => First

)

[2] => Array
(
[FULL_NAME] => Two, One
[LAST_NAME] => Two
[FIRST_NAME] => One

)
)


The sub-arrays in the example are just 2 but there can be many more.

Can anyone tell me how I can replace the value of all the FULL_NAME to display FIRST_NAME followed by LAST_NAME without a comma?

Any suggestions would be great

thanks
3:10 pm on Jan 20, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2004
posts:941
votes: 0


are you talking about something like this?

$names[0]['FULL_NAME'] = $names[1]['FIRST_NAME'].' '.$names[0]['LAST_NAME']


You can easily loop in an array using something like:

foreach ($names as $custNames)
{
$custNames['FULL_NAME'] = $custNames['FIRST_NAME'].' '.$custNames['LAST_NAME'];
}
6:31 pm on Jan 20, 2011 (gmt 0)

New User

5+ Year Member

joined:Jan 19, 2011
posts:28
votes: 0


I'd say more like this...

$i = 1;
while(isset($mynames[$i]))
$mynames[$i]['FULL_NAME'] = $mynames[$i]['FIRST_NAME'] . $mynames[$i]['LAST_NAME'];
$i++;
break;