小编cbo*_*urn的帖子

检查PHP中多个数组索引的值

我想检查一组图像文件名,看看有多少连续图像使用PHP具有相同的方向.

在下面的示例中,我想知道索引1到4具有相同的方向,或者在第一个索引处有四个具有相同方向的连续图像.

作为参考,"方向"值对于垂直方向是"V"而对于水平方向是"H".

例如,

Array
(
[0] => Array
    (
        [filename] => image0.jpg
        [orientation] => V
    )

[1] => Array
    (
        [filename] => image1.jpg
        [orientation] => H
    )

[2] => Array
    (
        [filename] => image2.jpg
        [orientation] => H
    )

[3] => Array
    (
        [filename] => image3.jpg
        [orientation] => H
    )

[4] => Array
    (
        [filename] => image4.jpg
        [orientation] => H
    )
[5] => Array
    (
        [filename] => image5.jpg
        [orientation] => V
    )
[...]
[n]
}
Run Code Online (Sandbox Code Playgroud)

必须有一个更好的方法

if ([i]['orientation'] == [i+1]['orientation']) …
Run Code Online (Sandbox Code Playgroud)

php arrays

4
推荐指数
1
解决办法
465
查看次数

使用参数作为变量名(Javascript)

我似乎找不到直接回答这个问题的问题。

我想使用函数参数作为该函数内变量的名称。

例如,

test(var1);

function test(foo)
{
    var foo = 'Hello world!'; // Set var1
}

alert(var1); // Hello world!
Run Code Online (Sandbox Code Playgroud)

我可以在这里使用括号(即 window.[ ])吗?

javascript arguments function

1
推荐指数
1
解决办法
8628
查看次数

标签 统计

arguments ×1

arrays ×1

function ×1

javascript ×1

php ×1