PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 21, 2014 2:23 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Jul 06, 2012 4:55 pm 
Offline
Forum Newbie

Joined: Wed Feb 15, 2012 12:55 am
Posts: 6
Hi all,

I have an array of several hundred names. I need to insert the name of spouse into the array.

How do I insert Jane Doe after John Doe?

Thanks in advance for your help.

Syntax: [ Download ] [ Hide ]
$array = ("John Smith", "John Doe", "John Jones");

$spouse1 = "John Doe";
$spouse2 = "Jane Doe";

// I want array to be...
// $array = ("John Smith", "John Doe", "Jane Doe", "John Jones");


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 5:48 pm 
Offline
Forum Newbie

Joined: Wed Feb 15, 2012 12:55 am
Posts: 6
Solved

Syntax: [ Download ] [ Hide ]
$array = array("John Smith", "John Doe", "John Jones");$spouse1 = "John Doe";$spouse2 = "Jane Doe";             function insert_after($array,$search,$add){     $key = array_search($search,$array);    if($key !== false)      {               array_splice($array,$key+1,0,array($add));      }       return $array;}$array = insert_after($array, $spouse1, $spouse2);


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 guests


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

Jump to:  
Powered by phpBB® Forum Software © phpBB Group