REMEMBER PHP

MINTE9
2REMEMBER




Last update:   23-07-2021

Rererence

In PHP variables are NOT passed by reference (& needed)
 
$a = 1; 
$b = $a; 
$a = 2;

echo $b; // 1

$a = 1; 
$b = &$a;
$a = 2;

echo $b; // 2
... 5 more rows
˄˄˄

Array

Reference with foreach changes the array.
 RunCode
$arr = array('1', '2', '3', '4');

foreach ($arr as &$val) {
    $val *= 2;
}

print_r($arr); // [2, 4, 6, 8]
... 2 more rows
˄˄˄

Walk

 
$a = [1.5, 2.6, 3.7];

// array map
$b = array_map('floor', $a); // [1, 2, 3]

print_r($a); // [1.5, 2.6, 3.7]

// array walk
array_walk($a, function(&$v) { 
    $v = floor($v); 
});

print_r($a); // [1, 2, 3]
... 6 more rows
˄˄˄
Task

 CompleteTask
/**
 * Round up array values
 * Use array_map() with built-in ceil functions
 * The result array $mapped will be [2, 3, 4]
 */
$arr = [1.5, 2.6, 3.7];
...


/**
 * Round up array values
 * Use array_walk() with reference
 * The array will be [2, 3, 4]
 */
$arr = [1.5, 2.6, 3.7];
...
solution code
Questions    
No. 5   Integers
CARD
04
96

        A B C D E F
🔔
1/2