<?php
$arr = [
'name1' => 'apple',
'name100' => 'jaguar'
];
$str = '[name1]';
echo finder($arr, $str);
echo PHP_EOL;
echo finder(
$arr,
'[name2][name1][name100]'
);
function finder($arr, $str) {
$output = '';
foreach($arr as $key=>$value) {
$pattern = "/\[{$key}\]/";
preg_match($pattern, $str, $matches);
if (count($matches) > 0 ) {
$output .= $arr[$key] . PHP_EOL;
}
}
return $output;
}
$('#add-image').click(function(e) {
e.preventDefault();
var image = wp.media({
title: 'Upload Image',
multiple: false
}).open()
.on('select', function(e){
var uploaded_image = image.state().get('selection').first();
console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
});
});
echo '<input type="radio" name="test" value="1" '.($_GET["test"] == 1? "checked":"" ).'>1<br>';
echo '<input type="radio" name="test" value="2" '.($_GET["test"] == 2? "checked":"" ).'>2<br>';
echo '<input type="radio" name="test" value="3" '.($_GET["test"] == 3? "checked":"" ).'>3<br>';
echo '<input type="submit" value="go"><br>';