How do I make an array from specific keys in another array?
OK, I'm exhausted after spending 10 hours researching and testing, but to no avail.
I have an array, which is along the lines of ...
How do I create a new array to contain only firstnames and lastnames please?
19 Replies
select firstname, lastname from table
do you know what, i just realised that as i read it back
i've been playing with the complete array
what do you mean?
i read the full table into an array, and tried to change THAT array
yup, therefore my answer
you just need to read the data you need, and you get what you want
it's also a lot more performant
i needed all the data initially though to analyse something first. I just need to revisit the table
do you still need all the data?
not after analysing it, no, which was why i just wanted to either remove the fields i did not need, or make a new array with what i did
but easier to re-read the table
having said that, it would be useful to know how to make a new array from an existing one
another time i might need firstnames and age
you have 2 options: for or array_map
my preference would be the one with the least code 😄
for:
array_map:
wow, that seems very straight forward
it's way easier than it feels like
that worked perfectly @ array_map
i shall make a note of both though, thank you very much 🙂
you're welcome
this should save re-reading from the database
indeed ... now i shall take a well earned break and drink a bucket of coffee 😄
i would skip on the bucket of coffee, at this time
it's only 21:20 here
7hours till bedtime
terrible time to drink coffee