質問
私は、指定された配列が別の配列に一致するかどうかを確認する必要があります。私は最初の配列を操作するか、またはそれにいくつかの他の方法と一致する方法を見つけ出すことはできません。
私はこの配列を一致させる必要があります:
Array
(
[1] => site
[2] => blog
[3] => index.php
)
これを一致させます
Array
(
[site] => Array
(
[path] => site
[name] => site
[kind] => directory
[content] => Array
(
[404] => Array
(
[path] => site/404.php
[name] => 404.php
[extension] => php
[kind] => file
)
[blog] => Array
(
[path] => site/blog
[name] => blog
[kind] => directory
[content] => Array
(
[contact] => Array
(
[path] => site/blog/contact.php
[name] => contact.php
[extension] => php
[kind] => file
)
[index] => Array
(
[path] => site/blog/index.php
[name] => index.php
[extension] => php
[kind] => file
)
[about] => Array
(
[path] => site/blog/about.php
[name] => about.php
[extension] => php
[kind] => file
)
)
)
[index] => Array
(
[path] => site/index.php
[name] => index.php
[extension] => php
[kind] => file
)
)
)
)
、ファイルの内容の配列を返します:
[index] => Array
(
[path] => site/blog/index.php
[name] => index.php
[extension] => php
[kind] => file
)
ヘルプをいただければ幸いです!
解決
配列にだけインデックスます:
$b[$a[1]]['content'][$a[2]]['content'][str_replace('.php', '', $a[3])]
あなたの入力は、変数の長さとすることができる場合は、、代わりにループ内でこれを行います。
他のヒント
あなたが必要なので...
$array2[$array[1]][content][$array[2]][substr(0, stripos($array[3], "."), $array[3])]
またはそれに近い何か...
私はそれはあなたが、より大きな配列のインデックスのリストを確認し、/マッチング利用可能なすべての結果を返すようにしたい意味することはできますか?もしそうなら、そしてあなたの最初の配列を想定したが$indexes
と呼ばれ、あなたの目はあなたができる$results
と呼ばれています:
$found = array();
foreach($indexes as $index) {
if(isset($results[$index])) {
$found[] = $results[$index]['content'];
}
}
と今は中$インデックスのインデックスにマッチした検索結果がありました$コンテンツエントリのすべてのリストを$found
を持っていると思います。ホープことができます。
$path = array('site', 'blog', 'index.php');
$node = array(...); // the tree
for ($i = 0; $i < count($path) && !is_null($node); ++$i) {
$p = $path[$i];
$items = $i ? $node['content'] : $node;
$n = null;
foreach ($items as $it) {
if ($it['name'] == $p) {
$n = $node['content'][$p];
break;
}
}
$node = $n;
}
所属していません StackOverflow