Possible Duplicate:
A conditional element inside an array(…) construct
Here is my code
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
if (isset($product_option_value_description_query->row['smallimage'])) {
'smallimage' => $product_option_value_description_query->row['smallimage'],
}
'name' => $product_option_value_description_query->row['name'],
'price' => $product_option_value['price'],
'prefix' => $product_option_value['prefix']
);
can i do something like this....
here is my error
Parse error: syntax error, unexpected T_IF, expecting ')' in /Users/mattelhotiby/Sites/posnation/shop_pos/catalog/model/catalog/product.php on line 419
Actually i did this
if (isset($product_option_value_description_query->row['smallimage'])) {
$smallimage = $product_option_value_description_query->row['smallimage'];
}else{
$smallimage = '';
}
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'smallimage' => $smallimage,
'name' => $product_option_value_description_query->row['name'],
'price' => $product_option_value['price'],
'prefix' => $product_option_value['prefix']
);
But i still want to know f there is a way to do an if within this array declaration
If that array is at that first state of [1], and "one". equals(match) then it sets the array to arrayCount[2] and then from there on. Basically, if "one" = match, it should set arrayCount to 2, if "two" = match AND the first if statement has already been executed, it will play the test sound.
php $LibraryStatus='true' $arrLayout = array( "section1" => array( if $LibraryStatus='true' ( "wLibrary" => array( "title" => "XBMC Library", "display" => "" ), else blank. if $ControlStatus='true' ( "wControl" => array( "title" => "Control", "display" => "" ) ) ) ?>
The function in_array() returns true if an item exists in an array. You can also use the function array_search() to get the key of a specific item in an array.
Not an if, but a similar thing is possible:
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'smallimage' => (isset($product_option_value_description_query->row['smallimage'])) ?
$product_option_value_description_query->row['smallimage'] : null,
'name' => $product_option_value_description_query->row['name'],
'price' => $product_option_value['price'],
'prefix' => $product_option_value['prefix']
);
Syntax:
(<statement> ? <case: true> : <case: false>)
(1 == 1 ? 'yes!' : 'PHP is wrong')
Maybe this one?
$array = array(
'key1' => 'value1',
'key2' => 'value2',
);
if (isset(...)) {
$array['key3'] = 'value3';
}
$multiarray[] = $array;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With