【发布时间】:2015-04-22 05:40:38
【问题描述】:
我有下面的 php 数组 $tempStyleArray,它是通过吐出一个字符串来创建的。
$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
帮我解决这个问题?我的数组格式有问题吗?
【问题讨论】: