I am trying to do foreach inside array. I am trying to generate the select box using array value everything seems ok when i give a value manually.
array(
'name' => __('Testing Selection', 'test'),
'id' => 'testing',
'css' => 'min-width:150px;',
'std' => '2',
'default' => '2',
'type' => 'select',
'options' => array(
'1' => __('Test1', 'test'),
'2' => __('Test2', 'test'),
'3' => __('Test3', 'test'),
),
),
In the above code options key contains three values like 1, 2, 3 and the above code is working. But i want to loop all product id here using foreach but it seems not working for me may be i am trying a wrong way. I know foreach inside array is invalid that's why i am trying this way.
$foos = array(
'name' => __('Testing Selection', 'test'),
'id' => 'testing',
'css' => 'min-width:150px;',
'std' => '2',
'default' => '2',
'type' => 'select',
'options' => array(),
),
After array i did foreach
$args = array('post_type' => 'product', 'posts_per_page' => '-1');
$getproducts = get_posts($args);
foreach ($getproducts as $product) {
$foos['options'][] = array(
$product->ID => $product->get_title,
);
}
I want to list 20 more products in the select box everything manually is hard to me can anyone suggest me to use the foreach inside array?