Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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 strpos不起作用_Php_Arrays - Fatal编程技术网

PHP strpos不起作用

PHP strpos不起作用,php,arrays,Php,Arrays,列表数组: [lists] => Array ( [0] => Array ( [ID] => 1 [Name] => Bunglows [Property_type] => [Status] => Open

列表数组:

[lists] => Array
        (
            [0] => Array
                (
                    [ID] => 1
                    [Name] => Bunglows
                    [Property_type] => 
                    [Status] => Open
                )

            [1] => Array
                (
                    [ID] => 2
                    [Name] => Tenament
                    [Property_type] => 
                    [Status] => Open
                )

        )
设施类型数组:

[amenitytypes] => Array
        (
            [0] => Array
                (
                    [ID] => 13
                    [Name] => College
                    [Amenity_property_ID] => 14
                    [Property_name] => Bunglows,Tenament
                )

        )
PHP函数

                  <?php foreach($lists as $list):?>
                    <?php if(strpos(trim($amenitytype['Property_name']), trim($list['Name'])) == TRUE):?>
                      <label class="checkbox-inline">
                        <input type="checkbox" id="checkbox" class="Propertytype" value="<?php echo $list['ID']?>" checked> <?php echo trim($list['Name']);?>
                      </label>
                    <?php else:?>
                      <label class="checkbox-inline">
                        <input type="checkbox" id="checkbox" class="Propertytype" value="<?php echo $list['ID']?>"> <?php echo trim($list['Name']);?>
                      </label>
                    <?php endif;?>
                  <?php endforeach;?>


如果使用$AmentityType['Property_name'],请更改使用多维数组的行。$AmentityType数组中的名称属性\u name中没有属性

if(strpos(trim($amenitytype['Property_name']), trim($list['Name'])) == TRUE):?>


您应该使用
!==FALSE
而不是
==TRUE
,因为strpos可能会返回0,这将被视为非TRUE,而实际上它指向草堆中的第一个字符

另外,您的代码不清楚
$AmentityType
包含什么内容,因此您可能必须替换此行

用这个


使用
!=false
相反,我知道这可能是我的偏好。。但是为什么不直接使用
{…}
(大括号)而不是
:。。。endif?似乎有点不必要…兄弟列表是嵌套的foreach。所以我不能这样写$AmentityType[0]['Property\u name']
if(strpos(trim($amenitytype[0]['Property_name']), trim($list['Name'])) !== false):?>