Skip to content

Tag: php

While loop on multi-dimensional array

So I have a function that currently has a foreach and it works amazing, but I’m being forced to change it to a while loop: PLEASE NOTE: The developers at my company don’t want to use the foreach and they think that a while loop would be more efficient, but I’m not understanding how that woul…

How to get class from a constant array?

I have about twenty different classes that are segregated in an assoc array similar to this: But now I want to do the array constant. I can make it using const VAL = array(); just fine. The problem lies in making new objects using those classes fails with Parse error: syntax error, unexpected ‘[‘,…

Laravel 8.53 – Routing doesnt work on any of pages

Solution The solution was found thanks to @Gert B. Simply add to your Laravel application any virtual host (I added for mine) laravel1.test How to add Virtual host: Go to C:WindowsSystem32driversetchosts add line: 127.0.0.1 laravel1.test (or your virtual host name) And add this to your vhosts(in case of using…

Laravel find rows by nested relationship column

I have 2 tables reserves and chats, chats belongTo reserves and I want to get all chats where chat.reserve.user_id = Auth::id(). How can I do that in laravel. Answer I don`t know your models name (need more code in question), but try use where ‘reserves’ your relationship and have field user_id. M…

d3.js – PHP Array format

I need to create a d3.js chart using PHP formatted array for JSON. The format is like: The array code and format that I currently have is below. The format of the array clearly needs to be changed, but I’m not sure how to do that to suite the above format. Answer The best approach may be to create your

php can not get array value from an array

I have an array: And I would like to get the first value in the array: I have tried each of the following: array_values($_array)[0]; $data[0]; array_keys($data)[0]; But none of them work, and I instead get an empty string. I need to get the first element or key of the array. Answer you can use array_key_first…