/    Sign up×
Community /Pin to ProfileBookmark

Multi-dimensional arrays in a foreach loop?

Ok, so I’m not used to using the foreach loop, so tell me if this is (in theory) getting too complicated to work…

First, I have a function that gets all of the info I need from my database, it returns an array sort of like this:

[code=php]
$myrow[0][‘id’] = ‘165’;
$myrow[0][‘name’] = ‘Sally’;
$myrow[0][‘age’] = ’23’;
$myrow[0][‘status’] = ‘Employed’;
[/code]

Ok, so then I use this to try and process the data: … sort of.

[code=php] foreach(pullData(‘SELECT from myDB WHERE name = Sally’) as $value){
list(‘id’,’name’,’age’,’status’) = $value;
// Do whatever you were going to do with the data… code goes here.
}[/code]

My intent is to grab each row as I go in the easiest way possible (without having to re-type the “get data from the database” stuff each time I need to use it, just a quick “pullData($query)” function to grab everything… and then use it one line at a time [I]after[/I] it gets stored in the list…

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @amandaNHT spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...