Concatenating strings in arguments (php) Concatenating strings in arguments (php) wordpress wordpress

Concatenating strings in arguments (php)


your following statement will work fine:

$o = get_post_meta($id, 'locationForDay'.$i, true);

Although, if you are unsure you can always throw parenthesis around a string:

$o = get_post_meta($id, ('locationForDay'.$i), true);

Edit: It should be worth noting that it is possible to concatenate strings using a comma (,). Therefore the following statement would NOT work:

$o = get_post_meta($id, 'locationForDay',$i, true);

Whereas, the above statement would call the function get_post_meta and contain 4 arguments. In this instance it would be crucial to include the parenthesis in order to achieve your string concatenation:

$o = get_post_meta($id, ('locationForDay',$i), true);


$o = get_post_meta($id, ('locationForDay'.$i), true);

or

$o = get_post_meta($id, ('locationForDay'.$i.''), true);

or

$o = get_post_meta($id, ('locationForDay',$i,''), true);


Yes, you can concat variables as they are being passed into a function like that.