purencool Posted July 28, 2011 Share Posted July 28, 2011 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? $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'); Quote Link to comment https://forums.phpfreaks.com/topic/243039-array_combine-problem/ Share on other sites More sharing options...
premiso Posted July 28, 2011 Share Posted July 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243039-array_combine-problem/#findComment-1248252 Share on other sites More sharing options...
purencool Posted July 28, 2011 Author Share Posted July 28, 2011 thank you that solved the issue Quote Link to comment https://forums.phpfreaks.com/topic/243039-array_combine-problem/#findComment-1248260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.