There are 4 valid ways of defining a string, see this question for more details.
However in your case there is a special exception provided by PHP. Most users are unaware of it however, and it does leave ambiguities, as it’s no longer possible to tell a string literal, a constant, or a define apart, making it very difficult for other programmers to read your code ( e.g. yourself in 9 months time ).
So your code:
for($i=1; $i<= $myoptionValue[fieldcount]; $i++)
{
$arguments .= ',"index"'.$i.'=>'.$myoptionValue[id.$i];
}
Is trying to append a string to the end of an array, which doesn’t work. Arrays aren’t strings, and you can only use the .=
and .
operators on strings. Also $myoptionValue[id.$i]
violates the special case situation as the expression is now ambiguous ( does it mean ‘id.$i’, ‘id’.$i, or “id.$i”? )
To add an item to an array you need to do one of the following:
$arr = array();
$arr['key'] = 'value';
$arr[] = 'value without a key';
array_push( $arr, 'value1', 'value2', 'value3', etc... );
So your loop should be:
for ( $i=1; $i <= $myoptionValue['fieldcount']; $i++ ) {
$arguments['index'.$i] = $myoptionValue['id'.$i ];
}