【发布时间】:2012-08-03 18:09:15
【问题描述】:
我正在尝试从长数组值中获取字符串。
例如
$array[1]='this is a good day. The number:1, class:math';
$array[2]='this is a bad day. The number:2, class:english';
$array[3]='this is a fine day. The number:3, class:physics';
我想从数组中取出 number:1 或 class:math 字符串。
我试过了
echo array_search('number:1',$array);
但它什么也没给我。我想知道是否有更好的方法来做到这一点。非常感谢!
【问题讨论】:
-
你读过documentation了吗?
-
array_search搜索数组元素,而不是数组元素中字符串的内容。您是在尝试查找包含 某个键/值对 的 元素,还是在尝试查找 某个元素中某个键的值我>? -
那么,您到底想做什么?你希望它返回什么?
-
参见w3schools.com/php/php_arrays.asp,特别是在“多维数组”下
-
您将不得不更加努力地解释您需要什么、您希望如何使用它、您期望返回什么等