/    Sign up×
Community /Pin to ProfileBookmark

Question about php arrays

Hi all,

I’d like to know why PHP Arrays Suck?? How to store Values in 2D array Dynamically, So that using one value i can access other?
also without using indexes.

Anyone help me?

Thank in advance.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jul 24.2008 — You cannot access an array value without indices in any language. Maybe you should be a little more specific about what your problem is?
Copy linkTweet thisAlerts:
@FrankTheTankJul 25.2008 — You can insert values into an array without specifying an index, like so...

$arrayVal[] = "new thing"; //assigns an index for you

$arrayVal[] = "other new thing"; //assigns another index for you.

You can also access the values without knowing the explicit index values using foreach.

However, as [B]Declan1991[/B] says, you can't touch an array without indexes. In my first example numerical indices will be assigned automatically. The foreach statement will iterate over each index of an array, though you may not know what they are explicitly. php does know what they are and can tell you if you use the foreach($array as $key => $value) version of the foreach statement.

Frank
Copy linkTweet thisAlerts:
@cktsJul 25.2008 — I think what you're talking about is what I'm trying to do...

You know how facebook shows a 2 row/3 column table to randomly display 6 of your friends?

I want to know how I can select 6 random friends from the "friends" table in my MySQL database, to display the avatar and friend's name in each column...

ie.

$name[1], $avatar[1]

$name[2], $avatar[2]

etc.

Its hard to explain, but do you get what I mean?
Copy linkTweet thisAlerts:
@SyCoJul 25.2008 — Hi all,

I'd like to know why PHP Arrays Suck??[/QUOTE]

err, they don't. I'd like to know why you think they do? ?
How to store Values in 2D array Dynamically, So that using one value i can access other?

also without using indexes.[/QUOTE]


This really doesn't make a lot of sense.
>How to store Values in 2D array Dynamically

Is there any other way?

>So that using one value i can access other?

loop and compare?

>also without using indexes.

You don't like arrays, you don't like indexes. Maybe programming just isn't for you. Have you considered running a cheese shop? ?


I imagine the problem is easier than you might think but without knowing the problem and only being asked for a solution then it's a bit tricky coming up with that solution.

@ckts

You might want to post your own thread about your issue. I don't know how you get Facebook picture profiles from this post? What you need to do is not too hard but I'm not taking the OPs thread of topic. (short answer, little divs in a big div)
Copy linkTweet thisAlerts:
@cktsJul 25.2008 — Because I was thinking that you'd need numbered arrays for output in an HTML file table, because I don't think (and don't know how) you can loop into columns.

And a lot of the stuff on the internet doesn't go clearly into depth about how you take the returned rows and put them into numbered arrays.
Copy linkTweet thisAlerts:
@SyCoJul 25.2008 — ckts this is Komrads thread. His issue is arrays, yours is displaying images in columns. Your issue might be related because it might use arrays but you're dragging it off topic. Arrays are used everywhere in PHP but not all topics need to be posted here.
Copy linkTweet thisAlerts:
@komradauthorJul 28.2008 — @SyCo

Well, i am newbie in learning PHP. So, do you have any solutions? I didn't know if you're a newbie too. ?
Copy linkTweet thisAlerts:
@SyCoJul 28.2008 — At the risk of being accused of repeating myself.

>without knowing the problem and only being asked for a solution then it's a bit tricky coming up with that solution.
×

Success!

Help @komrad 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...