vendredi 30 janvier 2015

Parse error: syntax error, unexpected 'if' (T_IF), expecting ')'

How can I add a condition inside a php array?


Here is the array



$content['custom_fields'] = array(
array( "key" => "_yoast_wpseo_focuskw", "value" => $_POST["title"] ),
array( "key" => "_yoast_wpseo_metadesc", "value" => $_POST["titleenfa"] ),
array( "key" => "_yoast_wpseo_metakeywords", "value" => $_POST["metakey"] ),
if($_POST["link128"]){
array( "key" => "_link128", "value" => "field_54b398292c295" ),
array( "key" => "link128", "value" => $_POST["link128"] ),
}
if($_POST["link256"]){
array( "key" => "_link256", "value" => "field_54b398092c294" ),
array( "key" => "link256", "value" => $_POST["link256"] ),
}
if($_POST["link320"]){
array( "key" => "_link320", "value" => "field_54b3965495d27" ),
array( "key" => "link320", "value" => $_POST["link320"] ),
}
array( "key" => "country", "value" => "USA" )
);


But I get the PHP Parse error, why I can add a condition inside the array, what's happen??:



Parse error: syntax error, unexpected 'if' (T_IF), expecting ')'



Aucun commentaire:

Enregistrer un commentaire