Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/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 如何计算数组正则表达式中出现的图像数_Php_Arrays_Regex - Fatal编程技术网

Php 如何计算数组正则表达式中出现的图像数

Php 如何计算数组正则表达式中出现的图像数,php,arrays,regex,Php,Arrays,Regex,我有一个类似这样的数组 ARRAY[0][DATAROOT.PROPIEDADES.FOTO1][0] ARRAY[0][DATAROOT.PROPIEDADES.FOTO2][0] ARRAY[0][DATAROOT.PROPIEDADES.FOTO3][0] ARRAY[0][DATAROOT.PROPIEDADES.FOTO4][0] 我必须编写一个脚本来计算阵列中的照片数: $x = "DATAROOT.PROPIEDADES.FOTO"; $ct = 8; // This is t

我有一个类似这样的数组

ARRAY[0][DATAROOT.PROPIEDADES.FOTO1][0]
ARRAY[0][DATAROOT.PROPIEDADES.FOTO2][0]
ARRAY[0][DATAROOT.PROPIEDADES.FOTO3][0]
ARRAY[0][DATAROOT.PROPIEDADES.FOTO4][0]
我必须编写一个脚本来计算阵列中的照片数:

$x = "DATAROOT.PROPIEDADES.FOTO";

$ct = 8; // This is the number of image I am passing fixed variable
我想用数组得到它,我需要找到一种计算数组的方法

它的列名为
DATAROOT.PROPIEDADES.FOTO
,最后是
1
2
3

这是我做不到的

for($tt=1;$tt<=$ct;$tt++)
{   
    $k=$x.$tt;     
    $result[]=$this->ARRAY[0][$k][0];
}
for($tt=1;$ttARRAY[0][$k][0];
}
有人能帮我吗


作为替代方案,您可以在父数组中获取其键具有该子字符串的元素:

$x = 'DATAROOT.PROPIEDADES.FOTO';
foreach($this->ARRAY[0] as $k => $value) {
    if(strpos($k, $x) !== false) {
        $result[] = $value[0];
    }
}
或:


数一数数组列?你已经在
$ct
@ghost中得到了它是的,但我应该动态得到它。因为我不知道数组中有多少图像。或者如果你建议其他方法来做这件事。那就太好了。该数组中还有其他索引没有命名为
DATAROOT.PROPIEDADES.FOTO
?@ghost是的,类似于
DATAROOT.PROPIEDADES.description
DATAROOT.PROPIEDADES.TITULO
etc@Vikram真高兴这有帮助
foreach($this->ARRAY[0] as $k => $value) {
    if(preg_match('~DATAROOT\.PROPIEDADES\.FOTO\d+~', $k)) {
        $result[] = $value[0]
    }
}