I have an array like this:
Array
(
[0] => Array
(
[id] => 9826
[tag] => \"php\"
)
[1] => Array
(
[id] =>
var availableTags = [
<?php
$tag_strings = array();
foreach($Tags as $tag){
$tag_strings[] = '"'.$tag['tag'].'"';
}
echo implode(",", $tag_strings);
?>
];
var availableTags = [
<?php
foreach($Tags as $tag){
echo '"'.$tag['tag'].'",';
}
?>
];
Save yourself some lines of code:
var availableTags = <?php
function get_tag($value) {
return $value['tag'];
}
echo json_encode(array_map("get_tag", $Tags));
?>
Try:
var availableTags = <?php
echo json_encode(array_map(create_function('$v','return $v[\'tag\'];'), $Tags));
?>;
<?php
$arr = array(
0 => array("id" => 9826, "tag" => "php"),
1 => array("id" => 9680, "tag" => "perl")
);
$my_array;
foreach($arr as $key=>$val) {
$my_array[] = $arr[$key]['tag'];
}
$availableTags = json_encode($my_array);
echo $availableTags;
?>