pinkotoad
03-15-2007, 01:54 AM
I am having problems coming up with the logic for combining multiple arrays.
<?php
/* this is the data im given, the number of sets will not always be 2,
could be more, or could just be 1 */
$data['title'] = 'Widget';
$data['price'] = 5;
$optionSets = array(
1 => array('id'=>1,'title'=>'Color'),
2 => array('id'=>2,'title'=>'Size'),
3 => array('id'=>3,'title'=>'Foofoo'),
);
$data['options'][1] = array(
array('id'=>1,'title'=>'Red','price'=>0),
array('id'=>2,'title'=>'Blue','price'=>.75),
array('id'=>3,'title'=>'White','price'=>.5),
);
$data['options'][2] = array(
array('id'=>4,'title'=>'Small','price'=>0),
array('id'=>5,'title'=>'Large','price'=>.5),
array('id'=>8,'title'=>'XLarge','price'=>1.5),
);
// this the array i need to end up with
$new_set = array(
array ('title' => 'Red Small', 'inc'=>0, 'id'=>array('4','1') ),
array ('title' => 'Red Large', 'inc'=>.5, 'id'=>array('5','1') ),
array ('title' => 'Blue Small', 'inc'=>2.5, 'id'=>array('5','2') ),
array ('title' => 'Blue Large', 'inc'=>3, 'id'=>array('5','2') ),
array ('title' => 'White Small', 'inc'=>3, 'id'=>array('5','3') ),
array ('title' => 'White Large', 'inc'=>3.5, 'id'=>array('5','3') ),
);
?>
Anyone have any ideas?
<?php
/* this is the data im given, the number of sets will not always be 2,
could be more, or could just be 1 */
$data['title'] = 'Widget';
$data['price'] = 5;
$optionSets = array(
1 => array('id'=>1,'title'=>'Color'),
2 => array('id'=>2,'title'=>'Size'),
3 => array('id'=>3,'title'=>'Foofoo'),
);
$data['options'][1] = array(
array('id'=>1,'title'=>'Red','price'=>0),
array('id'=>2,'title'=>'Blue','price'=>.75),
array('id'=>3,'title'=>'White','price'=>.5),
);
$data['options'][2] = array(
array('id'=>4,'title'=>'Small','price'=>0),
array('id'=>5,'title'=>'Large','price'=>.5),
array('id'=>8,'title'=>'XLarge','price'=>1.5),
);
// this the array i need to end up with
$new_set = array(
array ('title' => 'Red Small', 'inc'=>0, 'id'=>array('4','1') ),
array ('title' => 'Red Large', 'inc'=>.5, 'id'=>array('5','1') ),
array ('title' => 'Blue Small', 'inc'=>2.5, 'id'=>array('5','2') ),
array ('title' => 'Blue Large', 'inc'=>3, 'id'=>array('5','2') ),
array ('title' => 'White Small', 'inc'=>3, 'id'=>array('5','3') ),
array ('title' => 'White Large', 'inc'=>3.5, 'id'=>array('5','3') ),
);
?>
Anyone have any ideas?