Php – Multidimensional array and array_push

array-pusharraysPHP

I have a huge multidimensional array, let's name it $big_array.

In addition I have this set of data that I have to put into above array:

$input = array('one','two','three','four');

That's what I need to push into $big_array (based on $input from above):

 $value = array(
   'id' => $number,
   'title' => 'foo',
   'type' => 'options',
   'options' => array('one','two','three','four'),
   'page' => 'font_manager',
   );

  array_push($big_array, $value);

$big_array structure looks like this:

$big_array = array(
(...)

array(
 'id' => 'Bar',
 'title' => 'Foo',
 'type' => 'select',
 'page' => 'font_manager',
 ), 

 array(
  'id' => 'ss_font',
  'title' => __("Main font:",'solidstyle_admin'), 
  'type' => 'select',
  'page' => 'font_manager',
  'description' =>  __("This font will be used for all pages.",'solidstyle_admin'),
  'default' => '',
  'options' => array(
     'option1' => 'option1',
     'option2' => 'option12,
   ),
  ),

(...)
);

What I exactly want to do will look like that if it will be possible to include loops in arrays (yes, I know how wrong is that, just trying to explain it better):

$input = array('one','two','three','four');
$value = array(
       'id' => $number,
       'title' => 'foo',
       'type' => 'options',
       'options' => array(
         foreach($input as $number) {
           echo $number.',';
         };
        ),
       'page' => 'font_manager',
       );

Best Answer

I think what you are going for is getting

$input = array('one','two','three','four');

inserted into

$value = array(
   'id' => $number,
   'title' => 'foo',
   'type' => 'options',
   'page' => 'font_manager',
);

so that it looks like this:

$value = array(
   'id' => $number,
   'title' => 'foo',
   'type' => 'options',
   'options' => array('one','two','three','four'),
   'page' => 'font_manager',
);

and can then be pushed onto $bigArray . If that is the case, it should be as simple as

$input = array('one','two','three','four');
$value = array(
   'id' => $number,
   'title' => 'foo',
   'type' => 'options',
   'page' => 'font_manager',
);
$value['options'] = $input;
$bigArray[] = $value; // equivalent to array_push($bigArray, $value);

If I misunderstood your goal, please let me know.

edit: If you are going for something like this

$value = array(
   'id' => $number,
   'title' => 'foo',
   'type' => 'options',
   'options' => array('one,two,three,four'),
   'page' => 'font_manager',
);

then it you would just change

$value['options'] = $input;

to

$value['options'] = implode(",",$input);