Split value in foreach

Asked

Viewed 283 times

0

I need to take the value of two different arrays and put in the database, I tried with the code below, but I’m having difficulty to separate the two values and add each of the values to their respective database fields.

<?php

$array = array(12.1, 12.3, 18.32, 12.45, 1.5, 1.5);
$array2 = array(12.3, 2.3);

foreach(array_combine($array, $array2) as $key => $media) {
 $media = str_replace(",",".",$media); 
 $media_total = str_replace(",",".",$media_total); 
 var_dump($key, $media);
 var_dump($key, $media_total);
}
?>
  • 1

    Why don’t you make a loop for each one?

  • 1

    Has you in the array?

  • Respective table or meant respective fields?

  • I meant in the fields

  • One array has the simple media value and the other has the calculation with all medias

  • How do you need these values to be placed in the bank? Do you have any standards?

  • do not understand you have 2 arrays, have two variables $media and $media_total this with difficulty to average or put in the bank the value of variables?

  • My difficulty is in recovering the value of the two arrays, I can only recover from one

Show 3 more comments

1 answer

1


Take the array_combine from inside the foreach, because for each interaction it is combining the arrays again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.