D
D
Dmitry2017-09-13 12:32:35
PHP
Dmitry, 2017-09-13 12:32:35

How can you process an array?

Hello!
There is an array, I process it in this way:

foreach ($item as $k=>$val) {
                if($k == "date"){
                    $l[] = $val;
                }else{
                    $l[] = "'".$val."'";
                }
            }

Is it possible to make a decision using array_map?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eustatos, 2017-09-13
@muldy

<?php

$data = Array(
    'date' => '12.01.2017',
    'name' => 'John'
);
$res = $data;

array_walk(
    $res,
    function(&$value, $key) {
        $value =  $key == 'date' ? "'{$value}'" : $value;
    }
);

print_r($res);

F
Fortop, 2017-09-13
@Fortop

php.net/manual/en/function.array-walk.php
You should have enough examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question