0
なぜこの関数が私が定義した配列に何かをプッシュしていないのを理解しようとしています。私はprint_r $ location_matchesを空にします。要素を配列にプッシュする関数を作成するにはどうすればよいですか?
あなたは道ので、変数を変更したい場合は、参照によって通過を確認する必要があり$id = get_the_ID();
$location_matches = array();
function find_location_meta($location_id, $product_id, $location_matches_arr) {
$meta_info = get_post_meta($location_id);
$working_with = unserialize($meta_info[locations_products_carried][0]);
for ($i = 0; $i < count($working_with); $i++) {
if ($working_with[$i][locations_products][0] == $product_id) {
array_push($location_matches_arr, $working_with[$i]);
}
}
}
find_location_meta(94, $id, $location_matches);
配列を返すか、参照渡しする必要があります。 –
$ working_with = unserialize($ meta_info [locations_products_carried] [0]); - locations_products_carriedは変数のいずれかです。次に$記号が必要です。そうであれば文字列で、次に引用符が必要です。 $ meta_infoや$ working_withを使って "print_r"を試してみてください - あなたは一歩一歩進むことをお勧めします。 iterateを実行する前に$ working_withに要素があるかどうかを確認してください。それにはlocations_productsに問題があります(変数か文字列です)。そして、正しい$ location_idが確実に94ですか? –