Jump to content

array_combine problem


purencool

Recommended Posts

hi phpfreaks,

 

I have two arrays that I am trying to combine.  I have been trying to use array_combine but it is not working . The result I am trying to achieve is displayed in the bottom code box. Has anyone got any ideas? :shrug:

 

$ticketArray = array (
'customerId'=>array('fishing', "'/[^a-z_-\s]/i'"),
'businessName'=>array('housing', "'/[^a-z_-\s]/i'"),			
'title' =>array( "high rise", "'/[^a-z_-\s]/i'");

 

$arr = array ( 0 =>'',  1 =>'', 2 =>'', 3 => '');

 

$result = array_combine($arr,$ticketArray);
print_r($result);

 

 

I am trying to achieve this?

$arr = array ( 0 =>'fishing',  1 =>'housing', 2 =>'high rise');

Link to comment
https://forums.phpfreaks.com/topic/243039-array_combine-problem/
Share on other sites

There is no rhyme or reason to your combine, other than you want the first item of the subarrays to match up with the second array.

 

$arr = array();
foreach ($ticketArray as $key => $val) {
     $arr[] = $ticketArray[$key][0];
}
var_dump($arr);

 

Should get you what you want, but might need more information if it doesn't work like you expect it to with all data.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.