我正在研究一个WordPress项目,并从post meta获取数据。
Queue<Integer> q1 = new LinkedList<>()
/**
* Queue operations.
* Retrieves, but does not remove, the head (first element) of this list.
*
* @return the head of this list, or {@code null} if this list is empty
* @since 1.5
*/
此后,我将对象转换为此处的数组
$data_post = get_post_meta(get_the_ID(), 'map_pointers');
OutPut
array (size=1)
0 => string '{"1":[{"point_pp":"a","point_name":"a","point_position":"a","point_department":"a","point_address":"test address<br />Test Address 2","point_phone":"a","point_email":"test@gmail.com","pint":"1","postID":"35"},{"point_pp":"a","point_name":"a","point_position":"sad","point_department":"a","point_address":"test address","point_phone":"123456789","point_email":"test@gmail.com","pint":"1","postID":"35"}]}' (length=466)
它转换得很完美,但是之后,我将计数器添加到每个数组中
$data_post = (array) json_decode(trim($data_post[0],'"'));
上面的代码在PHP7.2或更高版本中工作正常,结果显示如下
$data_post = get_post_meta(get_the_ID(), 'map_pointers');
if(!empty($data_post)) {
$data_post = (array) json_decode(trim($data_post[0],'"'));
if(isset($data_post[$countPoint])) {
$data_post = (array) $data_post[$countPoint];
} else {
$data_post = null;
}
}
var_dump($data_post); // Shows null
我在做什么错?还是我必须为后备版本写点东西?