my array from $hasil is like this
Array ( [24] => 0.29883576167978 [20] => 0.29883576167978 [20,24] => 0.17930145700787 [34] => 0.12390406380914 [26,34] => 0.099123251047315 )
I'm try like this
$sameValue = array();
for ($i = 0; $i < sizeof($hasil) - 1; $i++) {
if (current($hasil) == next($hasil)) {
$sameValue[$i]['key'] = key($hasil);
$sameValue[$i]['value'] = current($hasil);
$sameValue[$i+1]['key'] = key($hasil);
$sameValue[$i+1]['value'] = next($hasil);
} else {
prev($hasil);
$sameValue[$i]['key'] = key($hasil);
$sameValue[$i]['value'] = current($hasil);
break;
}
}
and store in database like this.
$hasilInsert = array();
foreach ($sameValue as $key => $value) {
$hasilInsert = array(
'id_wi' => $wisatawan->id,
'hasil' => $value['key'],
'nilai' => $value['value']
);
$xy = HasilWisataTemp::insert($hasilInsert);
}
What's wrong in this code? Or any simple way to store same value array in database? Because I want store the array just the same value.
Thank for attention.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2luBgiJ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire