Is it possible to explode an array like this.
$arr=array();
$arr[0]['id']='123';
$arr[0]['otherdatas']=
$arr[1]['id']='234';
$arr[1]['otherdatas']=
$arr[2]['id']='567';
echo "string: ".explode($arr[]['id'],',');
and end up with this?
string: 123,234,567
Doing the above results in:
Fatal error: Cannot use [] for reading in /data/www/test.php on line 8
How can I go about this without doing something like…
function getIDs(){
foreach($arr as $val){
if($string){$string.=',';}
$string.=$arr['id'];
}
return $string;
}
Is there some better way to go about this?
First of all, you’re trying to
implodethe strings, notexplode. Secondly, no, there’s no syntax shortcut for expressing the operation “join allidkeys in all sub arrays together”. You can do it very concisely like this though: