How to match value/text Trykk
front when the result from var_dump($haystack) looks like this:
array(2) {
[0] => array(11) {
["id"] => string(13) "64085aafcb9db"
["type"] => string(10) "checkboxes"
["raw"] => array(1) {
[2] => string(5) "b3ygo"
}
["values"] => array(1) {
[0] => array(6) {
["label"] => string(11) "Trykk front"
["price"] => float(42)
["price_type"] => string(2) "qt"
["slug"] => string(5) "b3ygo"
["calc_price"] => float(42)
["pricing_hint"] => string(23) "(+kr 42)"
}
}
["clone_type"] => string(0) ""
["label"] => string(31) "Ønsker du trykk på produktet?"
["hide_cart"] => bool(false)
["hide_checkout"] => bool(false)
["hide_order"] => bool(false)
["clone_idx"] => int(0)
["calc_weight"] => bool(false)
}
[1] => array(11) {
["id"] => string(13) "64085aaf29908"
["type"] => string(4) "file"
["raw"] => string(0) ""
["values"] => array(1) {
[0]=>array(4) {
["label"] => string(0) ""
["price"] => int(0)
["price_type"] => string(4) "none"
["formatted_label"]=>string(31) ""
}
}
["clone_type"] => string(0) ""
["label"] => string(56) "Om du ønsker trykk på produktet laster du opp logo her"
["hide_cart"] => bool(false)
["hide_checkout"] => bool(false)
["hide_order"] => bool(false)
["clone_idx"] => int(0)
["calc_weight"] => bool(false)
}
}
$matches = preg_grep ('/^Trykk front (w+)/i', $haystack);
2
Answers
You can use array_filter like:
Fiddle
Based on your
var_dump
output, "Trykk front" is from$haystack[0]['values']
. So, assuming your code needs to be updated like this: