dilfdo
126
1
Laravel

how to save multii dimentional array in db rows

Posted 3 years ago by dilfdo

im getting following data through service url and i want to store it in my db

`` value = 1:1,2:0,3:1,4:0,5:1,6:1,7:0,8:0,9:1,10:0

i manage to make it in this way to get values seperate

$result = array();
                foreach (explode(',',$value) as $sub)
                {
                    $subAry = explode(':',$sub);
                    $result[$subAry[0]] = $subAry[1];

                }
                return $result;

this is how it return $result { "1": "a", "2": "b", "3": "c", "4": "d", "5": "v", "6": "h, "7": "0", "8": "0", "9": "l", "10": "0" }

i want to store those in rows two separetd columns.

my controller

`` $DriverPreDepartureItems = new DriverPreDepartureItems(); $DriverPreDepartureItems->user_id = $driver_id->id;

                $DriverPreDepartureItems->shift_id = $find_shift->id;
                $DriverPreDepartureItems->type = ;
                $DriverPreDepartureItems->value = ;

                $DriverPreDepartureItems->save();

below two are the columns whic values need to store. pls advice
$DriverPreDepartureItems->type = ; $DriverPreDepartureItems->value = ;

Please sign in or create an account to participate in this conversation.