Category : arrays

I can’t access this array. I tried everything. I need to get the values of [total:protected] and [lastPage:protected]. All of this is stored in $content. I tried: $content["total:protected"], $content->total:protected() laravelPaginationlar Object ( [total:protected] => 7 [lastPage:protected] => 1 [items:protected] => laravelHelperCollection Object ( [items:protected] => Array ( ) ) [perPage:protected] => 10 [currentPage:protected] => 3 ..

Read more

I develop a ticketing system which user have to choose the quantity of ticket category. I want to save the record to database by the total of quantity. But it seems to be failed. I end up only save the record by category id. Here is the result when I try to return it. and ..

Read more

I have four arrays to get data from those arrays i am using four different foreach loop $storagePeriodHistory = []; $consignmentHistory = []; $SaleOrderHistory = []; $purchaseOrderHistory = []; foreach ($storagePeriods as $storagePeriodID) { array_push($storagePeriodHistory, [0, $storagePeriodID, getInvoiceStatus($invoice->status), "This Storage Period is added in Invoice number " . $invoice->id]); } foreach ($consignments as $consignmentID) { ..

Read more

I tried to save data to the MySQL database and successfully saved data. I want to get JSON data in this formate { "response_code":0, "results":[ { "question":"Here is my question?", "correct_answer":"Correct Answer", "incorrect_answers":[ "wrong_1", "wrong_2", "wrong_3" ] } ] } But I am getting my JSON data in this format { "response_code":0, "results":[ { "question":"Here ..

Read more

I have the array: $csv=[ ["DATE"=>’2015-01-01T00:00:00′,"TMP"=>’+2′], ["DATE"=>’2015-01-01T01:00:00′,"TMP"=>’+1′], ["DATE"=>’2015-02-01T15:00:00′,"TMP"=>’+1′]] So i want to make an array: $datearr=[ ‘2015-01-01’=>[’00:00:00’=>’+2′, ’01:00:00’=>’+1′, ’02:00:00’=>’nodata’, ’03:00:00’=>’nodata’, ’04:00:00’=>’nodata’, ’05:00:00’=>’nodata’, ’06:00:00’=>’nodata’, ’07:00:00’=>’nodata’, ’08:00:00’=>’nodata’, ’09:00:00’=>’nodata’, ’10:00:00’=>’nodata’, ’11:00:00’=>’nodata’, ’12:00:00’=>’nodata’, ’13:00:00’=>’nodata’, ’14:00:00’=>’nodata’, ’15:00:00’=>’nodata’, ’16:00:00’=>’nodata’, ’17:00:00’=>’nodata’, ’18:00:00’=>’nodata’, ’19:00:00’=>’nodata’, ’20:00:00’=>’nodata’, ’21:00:00’=>’nodata’, ’22:00:00’=>’nodata’, ’23:00:00’=>’nodata’ ], ‘2015-02-01’=>[’00:00:00’=>’nodata’, ’01:00:00’=>’nodata’, ’02:00:00’=>’nodata’, ’03:00:00’=>’nodata’, ’04:00:00’=>’nodata’, ’05:00:00’=>’nodata’, ’06:00:00’=>’nodata’, ’07:00:00’=>’nodata’, ’08:00:00’=>’nodata’, ’09:00:00’=>’nodata’, ’10:00:00’=>’nodata’, ’11:00:00’=>’nodata’, ’12:00:00’=>’nodata’, ’13:00:00’=>’nodata’, ..

Read more

How can I create two separate arrays from a single associative array according to the value of array items? $data = array( array(‘user_id’=>’Coder 1’, ‘subject_id’=> 4096,’node’=>’first’), array(‘user_id’=>’Coder 2’, ‘subject_id’=> 2048,’node’=>’second’), array(‘user_id’=>’Coder 3’, ‘subject_id’=> 56756,’node’=>’second’), array(‘user_id’=>’Coder 4’, ‘subject_id’=> 34556,’node’=>’first’), array(‘user_id’=>’Coder 4’, ‘subject_id’=> 34556,’node’=>’second’), ); from the data array, I have to create two separate array based ..

Read more

This is my simplified code: $response[‘vat_details_no_coupon’] = []; $response[‘vat_details_no_coupon’][‘6.00’] = 3 * 0.6; Log::debug($response[‘vat_details_no_coupon’][‘6.00’]); Log::debug($response[‘vat_details_no_coupon’]); Log::debug(json_encode($response[‘vat_details_no_coupon’])); Output: local.DEBUG: 1.8 local.DEBUG: array ( ‘6.00’ => 1.79999999999999982236431605997495353221893310546875, local.DEBUG: {"6.00":1.79999999999999982236431605997495353221893310546875} Expected: local.DEBUG: 1.8 local.DEBUG: array ( ‘6.00’ => 1.8, local.DEBUG: {"6.00":1.8} What happens here and how can keep the clean numbers? Sourc..

Read more

I try to import JSON formatted file into MySQL database. I put this code in the web.php: Route::get(‘/pages’, function(){ $json = file_get_contents(storage_path(‘posts_and_comments.json’)); $objs = json_decode($json,true); foreach ($objs as $obj) { foreach ($obj as $key => $value) { $insertArr[Str::slug($key,’_’)] = $value; } DB::table(‘my_likes’)->insert($insertArr); } dd("Finished adding data in examples table"); }); It gave me a ErrorException ..

Read more

$users = DB::table(‘users’)->count(); //dd($users); for($i=0; $i<$users ; $i++){ $updated=DB::table(‘users’)->where(‘latehours’ , 0)->update([‘latehours’=>$total_hours[$i]]); $updated=DB::table(‘users’)->where(‘fine’ , 0)->update([‘fine’=>$fine[$i]]); } I have table named as users I want to update two columns of it latehours and fine respectively, both column are updating but with first value of array’s index, but my loop is not working. arrays are $total_hours and $fine. ..

Read more

In my Laravel project I’m trying to flatten an array to ensure consistency, for some reason, the attached screenshot showing my data format returned from my project won’t flatten with the flatten() method. I get an error: Error: Call to a member function flatten() on array Which is quite generic, I’ve tried using ->toArray() before ..

Read more