Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在运行if语句之前检查数组中的$meta_键是否有值_Php_Wordpress_If Statement_Multidimensional Array_Metadata - Fatal编程技术网

Php 如何在运行if语句之前检查数组中的$meta_键是否有值

Php 如何在运行if语句之前检查数组中的$meta_键是否有值,php,wordpress,if-statement,multidimensional-array,metadata,Php,Wordpress,If Statement,Multidimensional Array,Metadata,我正在编写一个代码,将信息从自定义字段发布到数据库 以下代码检查$meta_键是否存在: // Apply filters to keys $this->keys = apply_filters('sc_meta_keys', $this->keys); // See if the current meta_key is in the array keys if($this->in_array_recursive($meta_key, $this->keys)) {

我正在编写一个代码,将信息从自定义字段发布到数据库

以下代码检查$meta_键是否存在:

// Apply filters to keys
$this->keys = apply_filters('sc_meta_keys', $this->keys);

// See if the current meta_key is in the array keys
if($this->in_array_recursive($meta_key, $this->keys)) {

if($action == "add") {
//information from array gets added to DB
} 

}else{
//Do something else
}
但是,我不确定如何检查meta_键中是否有值,因为如果没有值,我不希望if语句运行


数组将始终具有键,但并非每个帖子都必须填充自定义字段

也许你应该这样做。这将检查$metakey是否存在

// See if the current meta_key is in the array keys
if (isset( $meta_key )) && (is_array($meta_key) && ($this->in_array_recursive($meta_key, $this->keys))) {

您应该始终检查是否设置了变量,并使用短路运算符来减少条件的处理时间。由于您尚未包含设置位置的逻辑,$meta_key我将检查是否已设置

$this->keys = apply_filters('sc_meta_keys', $this->keys);

// See if the current meta_key is in the array keys
if( isset( $meta_key ) && ! empty( $this->keys ) && $this->in_array_recursive( $meta_key, $this->keys ) ) {

    if($action == "add") {
        //information from array gets added to DB
    } 

    }
    else {
        //Do something else
}

不幸的是,它仍然在传递信息。我在sc_meta_keys函数中设置了如下键
$keys['lat'][]=“latitude”
$keys['lng'][]=“经度”
是否将其视为一个字符串(尽管是空的?@MrBiggRJD您正在设置数组值,因此它不会为空。