我有下面的php数组$tempStyleArray
,它是通过spiting一个字符串创建的。从php中的数组获取值的索引
$tempStyleArray = preg_split("/[:;]+/", "width: 569px; height: 26.456692913px; margin: 0px; border: 2px solid black;");
Array
(
[0] => width
[1] => 569px
[2] => height
[3] => 26.456692913px
[4] => margin
[5] => 0px
[6] => border
[7] => 2px solid black
[8] =>
)
我得从这个数组元素height
的index/key
。我尝试了下面的代码,但似乎没有为我工作。
foreach($tempStyleArray as $value)
{
if($value == "height") // not satisfying this condition
{
echo $value;
echo '</br>';
$key = $i;
}
}
在上述方案
它不会永远满足条件:(
$key = array_search('height', $tempStyleArray); // this one not returning anything
帮我解决这个问题?有没有我的阵列格式的任何问题?
那么如何将我的数组转换为这种格式? – chriz
你是如何得到这个数组的? –