我有一个数组
$_images['image[1]'] = image1.jpg
$_images['image[2]'] = image2.jpg
$_images['image[3]'] = image3.jpg
$_images['image[4]'] = image4.jpg
如何找到键中的最大数量/计数为 4,它与模式图像 [] 匹配。
感谢任何帮助。
我真的不明白你在问什么,但如果你的意思是
$_images[1] = 'image1.jpg';
$_images[2] = 'image2.jpg';
$_images[3] = 'image3.jpg';
$_images[4] = 'image4.jpg';
然后就做echo count($_images);
如果你的意思是
$images[1] = 'image1.jpg';
$images[2] = 'image2.jpg';
$images[3] = 'image3.jpg';
$images[4] = 'image4.jpg';
$_images = array();
array_push($_images, $images); //array of arrays
然后做
echo count($_images, COUNT_RECURSIVE) - 1; //keep in mind your parent array must only have 1 array inside it, or you have to do -x where x = number of your second-level arrays
如果你的意思是别的,那么你必须解释更多......
感谢马克 B!
count(preg_grep('/images[([0-9]+)]/', $_images));