Php: Split Arrays
I am still a beginner and I need some help. I've got an array like this; $_POST= Array ( [0] => aaa@gmail.com [1] => bbb [2] => ccc [3] => ddd [4] => eee [5] =>
Solution 1:
What this code does is create an associative array
with keys and values. Then we loop through and push values in to the values array
.
We also use htmlentities
on each value which is pushed.
If we echo
first element in the values array it will display value1
.
<?php$arr = [
"key1" => "value1",
"key2" => "value2"
];
$valuesArr = [];
foreach ($arras$key => $value) {
array_push($valuesArr, htmlentities($value));
}
?>
What you can do is replace my array with your array and change the names in the foreach
loop if you need too.
Solution 2:
foreach($somethingas$key => $val){
$a[] = $val;
}
var_dump($a);
Try this code. It will get only the values of that array.
Solution 3:
You can apply a function such as htmlentities()
to the values of an array by using array_map
:
$escapedArray = array_map('htmlentities', $_POST);
PHP documentation: array_map
Post a Comment for "Php: Split Arrays"