Posted by cb Thu 15th Mar 2007 01:01 - Syntax is PHP - 124 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers
PHP parser reported no syntax errors in this post!
  1. // I am having problems coming up with the logic for combining multiple arrays.
  2.     /* this is the data im given, the number of sets will not always be 2,
  3.         could be more, or could just be 1 */
  4.     $set[1] = array(
  5.         array('id'=>1,'title'=>'Red','inc'=>0),
  6.         array('id'=>2,'title'=>'Blue','inc'=>2.5),
  7.         array('id'=>3,'title'=>'White','inc'=>3),
  8.     );
  9.  
  10.     $set[2] = array(
  11.         array('id'=>4,'title'=>'Small','inc'=>0),
  12.         array('id'=>5,'title'=>'Large','inc'=>.5),
  13.     );
  14.  
  15.     // this the array i need to end up with
  16.     $new_set = array(
  17.         array ('title' => 'Red Small', 'inc'=>0, 'id'=>array('4','1') ),
  18.         array ('title' => 'Red Large', 'inc'=>.5, 'id'=>array('5','1') ),
  19.  
  20.         array ('title' => 'Blue Small', 'inc'=>2.5, 'id'=>array('5','2') ),
  21.         array ('title' => 'Blue Large', 'inc'=>3, 'id'=>array('5','2') ),
  22.  
  23.         array ('title' => 'White Small', 'inc'=>3, 'id'=>array('5','3') ),
  24.         array ('title' => 'White Large', 'inc'=>3.5, 'id'=>array('5','3') ),
  25.     );
  26. ?>

PermaLink to this entry https://pastebin.co.uk/11884
Posted by cb Thu 15th Mar 2007 01:01 - Syntax is PHP - 124 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers

 

Comments: 0