Category : arrays

I have this foreach ($item_id as $key => $no) { $input[‘price’] = $price[$key][‘price’]; $input[‘quantity’] = $quantity[$key]; $subtotal[] = [$input[‘price’]*$input[‘quantity’]]; } $total_price = array_sum($subtotal); When I dd($total_price) it return 0. When I dd($subtotal) it return my array like this array:3 [▼ 0 => array:1 [▼ 0 => 3000000 ] 1 => array:1 [▼ 0 => 3 ..

Read more

i have in database array like this -> {"1":{"id":"12","amount":"1","max_amount":"1","chances":"100"}, "2":{"id":"13","amount":"1","max_amount":"1","chances":"100"}} and im outputing this like this -> $drop = json_decode($enemi->drops, true); $drop_item = []; foreach ($drop as $id => $drop) { $item_id = $drop[‘id’]; $random_number = rand(1,100); if($drop[‘chances’] >= $random_number) { $amount = rand($drop[‘amount’],$drop[‘max_amount’]); $user->items = json_decode($user->items, true); $count = $amount; if(empty($user->items[$item_id])){ $count = $amount; ..

Read more

I have a column name test in which I am storing a JSON data and the data is like this { "id": 4030662213806, "buyer_accepts_marketing": true, "cancel_reason": null, "cancelled_at": null, "line_items": [ { "id": 10357822685358, "vendor": "Samsung-1", }, { "id": 10357822685358, "vendor": "Samsung-2", }, { "id": 10357822685358, "vendor": "Samsung-3", } ], } I am trying to ..

Read more

hello all so i have a question, i have a sql database that have object array inside it, it will be like this id array 1 {"id":1032,"prc":77},{"id":1033,"prc":97} 2 {"id":1032,"prc":85},{"id":1034,"prc":97} 3 {"id":1030,"prc":85},{"id":1031,"prc":97} 4 {"id":1032,"prc":90},{"id":1033,"prc":97},{"id":1035,"prc":97} and what i want to do is take every data with id 1032 that has prc greater than 80 with its so ..

Read more

I want to get value of option key from an json, eg: the array below should return 12 I have tried the following code but I always get ‘Undefined array key 0’ {{ $question->options[0][‘option’] }} the data is stored in a json column of mysql database, the laravel model is Question and column is options ..

Read more

Array Months array(8) { [0]=> string(2) "05" [1]=> string(2) "09" [2]=> string(2) "08" [3]=> string(2) "07" [4]=> string(2) "05" [5]=> string(2) "07" [6]=> string(2) "06" [7]=> string(2) "07" } string(41) "["05","09","08","07","05","07","06","07"]" Array Values of Months array(8) { [0]=> string(5) "20000" [1]=> string(5) "10000" [2]=> string(5) "10000" [3]=> string(5) "15000" [4]=> string(5) "10000" [5]=> string(5) "50000" ..

Read more

i have this kind of data returned +—-+———–+———–+——-+ | id | member_id | produk_id | value | +—-+———–+———–+——-+ | 1 | 0001 | p001 | 1000 | | 2 | 0001 | p002 | 500 | | 3 | 0002 | p001 | 50 | +—-+———–+———–+——-+ and i want to turn it into this +—-+———–+——+——+ ..

Read more

Code $drillDownChart = Loan::select(‘loan_type AS name’) ->groupBy(‘loan_type’) ->where(‘transaction_year’, $transyear) ->where(‘invalid’, false) ->get(); $drillDownChart->map(function($val)use($loanChartArr) { $val->id = $val->name; $val->data = $loanChartArr; return $val; }); Output var_dump(json_encode($drillDownChart)); string(340) "[{"name":"Hospitalization","id":0,"data":[[1,0],[2,0],[3,0],[4,0],[5,2],[6,1],[7,3],[8,1],[9,1],[10,0],[11,0],[12,0]]},{"name":"Salary","id":0,"data":[[1,0],[2,0],[3,0],[4,0],[5,2],[6,1],[7,3],[8,1],[9,1],[10,0],[11,0],[12,0]]},{"name":"Emergency","id":0,"data":[[1,0],[2,0],[3,0],[4,0],[5,2],[6,1],[7,3],[8,1],[9,1],[10,0],[11,0],[12,0]]}]" The $val->id = $val->name; should return "Hospitalization", "Salary" and "Emergency" but instead it returns 0. Notice if I change "id" to "ID", it shows the correct output. $drillDownChart->map(function($val)use($loanChartArr) ..

Read more

Code: $loans = Loan::select(‘date_release’) ->where(‘invalid’,false) ->where(‘transaction_year’, $transyear) ->get() ->groupBy(function($date) { return Carbon::parse($date->date_release)->format(‘m’); // grouping by months }); $loanmcount = []; $loanArr = []; foreach ($loans as $key => $value) { $loanmcount[(int)$key] = count($value); } for($i = 1; $i <= 12; $i++){ if(!empty($loanmcount[$i])){ $loanArr[$i] = $loanmcount[$i]; }else{ $loanArr[$i] = 0; } } $loanTypeCount = Loan::select([‘loan_type AS ..

Read more

How to remove some keys from an array inside another array in PHP? I have this structure: array ( 0 => array ( ‘num’ => ‘123’, ‘nome’ => ‘test 001’ ‘pontos’ => 68, ‘data_status’ => ’03/09/2021 10:05′, ‘uuid_status’ => ‘69450ea451ae11ea85ca309c23d3a0ed’ ), 1 => array ( ‘num’ => ‘345’, ‘nome’ => ‘test 002’ ‘pontos’ => 120, ..

Read more

I created a user dashboard where he can update his information. Everything is working good but I can’t update the display picture. The picture is storing in wamp64/temp folder instead of storing in the ‘storage/users’. UserController public function update(Request $request) { // $request->validate([ ‘name’ => [‘sometimes’, ‘nullable’, ‘string’, ‘max:255′], ’email’ => [‘sometimes’, ‘nullable’, ‘string’, ’email’, ..

Read more

These are the values i wanted to insert into the db, $name4 = $request[‘name4′]; $email4 = $request[’email4′]; $phone = $request[‘phone’]; $cat=$request[‘cat’]; $rname=$request[‘rname’]; $file = $request[‘file’]; $ingr = $request[‘ingr’]; $qty = $request[‘qty’]; $unit = $request[‘unit’]; $recp = $request[‘recp’]; $items= array( ‘ingredients’ => $ingr, ‘quantity’ => $qty, ‘unit’ => $unit ); And insert querry is as follows, ..

Read more

I am using Laravel, and want to migrate & seed this file: https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/master/csv/countries.csv My migration has a column called timezones and it is type json. In the Country class I cast the column as json also. An example of the value of the timezones column value is: "[{zoneName:’Antarctica/Macquarie’,gmtOffset:39600,gmtOffsetName:’UTC+11:00′,abbreviation:’MIST’,tzName:’Macquarie Island Station Time’},{zoneName:’Australia/Adelaide’,gmtOffset:37800,gmtOffsetName:’UTC+10:30′,abbreviation:’ACDT’,tzName:’Australian Central Daylight Saving Time’},{zoneName:’Australia/Brisbane’,gmtOffset:36000,gmtOffsetName:’UTC+10:00′,abbreviation:’AEST’,tzName:’Australian ..

Read more

$loanAmountbyMonth = Loan::select(‘date_release’,’amount_granted’) ->where(‘invalid’,false) ->where(‘transaction_year’, $transyear) ->get() ->groupBy(function($date) { return Carbon::parse($date->date_release)->format(‘m’); // grouping by months }); $loanmcount2 = []; $loanArr2 = []; foreach ($loanAmountbyMonth as $key => $value) { $loanmcount2[(int)$key] = $value; } return view(‘src/modules-crud’,compact(‘loanmcount2’)); Output: string(471) "{"9":[{"date_release":"2021-09-21","amount_granted":"10000"}],"5":[{"date_release":"2021-05-23","amount_granted":"10000"},{"date_release":"2021-05-23","amount_granted":"20000"}],"6":[{"date_release":"2021-06-17","amount_granted":"10000"}],"7":[{"date_release":"2021-07-18","amount_granted":"15000"},{"date_release":"2021-07-18","amount_granted":"50000"},{"date_release":"2021-07-18","amount_granted":"14000"}],"8":[{"date_release":"2021-08-22","amount_granted":"10000"}]}" My Desired Output: string(61) "{"9":"10000","5":"30000","6":"10000","7":"79000","8":"10000"}" I wanted to add the amount_granted under "7":[{"date_release":"2021-07-18","amount_granted":"15000"},{"date_release":"2021-07-18","amount_granted":"50000"},{"date_release":"2021-07-18","amount_granted":"14000"}] but I can only ..

Read more

I have to arrays and I have to find difference values from it. Here is my Laravel Controller code $product_list = Operation::where(‘kvit_id’, $kvit->id)->pluck(‘product_id’)->toArray(); $hamkor_products = ListProduct::where(‘user_id’, $newkvit->user_id)->pluck(‘product_id’)->toArray(); $operProductList = array_diff($product_list, $hamkor_products); dd($product_list, $hamkor_products, $operProductList); Here is result which I’m getting What kind of mistake I made? $operProductList is returns [] Sourc..

Read more