$array = [
['foo'],
['bar'],
'baz'
];
$array = [
[
'foo',
'a' => 'b'
],
[
'bar',
'a' => 'b'
],
'baz'
];
<?php
echo "Что есть:\r\n";
$array = [
['foo'],
['bar'],
'baz'
];
var_dump($arr);
echo "----------------------------------------------\r\n";
echo "Что хотим получить:\r\n";
var_dump([
[
'foo',
'a' => 'b'
],
[
'bar',
'a' => 'b'
],
'baz'
]);
echo "----------------------------------------------\r\n";
echo "Процесс:\r\n";
$add_array = [
'a' => 'b'
];
foreach ($array as $key => $value){
if(is_array($value)){
$array[$key] += $add_array;
}
}
echo "----------------------------------------------\r\n";
echo "Полученный результат:\r\n";
var_dump($array);
foreach
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' =>'inherit',
'posts_per_page' => -1,
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= wp_get_attachment_url( $image->ID );
}
http://example.com/video_url.m3u8
ffmpeg -i "http://example.com/video_url.m3u8" -c copy -bsf:a aac_adtstoasc "output.mp4"
$hesh[$a_attribute][1]=$b_value;
if (is_array($v)) {
array_walk_recursive_array($v, $callback);
function array_walk_recursive_array(array &$array, callable $callback) {
foreach ($array as $k => &$v) {
// if (is_array($v)) {
// array_walk_recursive_array($v, $callback);
// } else {
$callback(& $v, $k, $array);
// }
}
}
array_walk_recursive_array( $array, function( $v, $k, $array ) {
if ( is_array( $v ) ) {
$v = $v['a'] = 'b';
return $v;
}
else return $v;
});
echo
на return
function promo_block($atts, $content = null) {
extract(shortcode_atts(array(
"img" => '',
"description" => '',
"title" => ''
), $atts));
return '<div class="col-md-4 promo-block">
<img src="'.get_template_directory_uri().'/img/svg/'.$img.'.svg" height="64" alt="">
<h3>'.$title.'</h3>
<p>'.$description.'</p>
</div>';
}
add_shortcode("pb", "promo_block");
function change(string &$x)
{
$x = trim($x);var_dump($x);
}
$v = " bar ";change($v);var_dump($v);
function change(string &$x0 = "", string &$x1 = "", string &$x2 = "")
{
for ($i = 0; $i < func_num_args(); $i++)
{
$s = "x{$i}";$$s = trim($$s);
}
}
$v = " bar ";$w = " foo ";
change($v);var_dump($v, $w);
change($v, $w);var_dump($v, $w);
придумали ли программисты в PHP