/    Sign up×
Community /Pin to ProfileBookmark

Associative PHP Arrays

Folks,

On my tests, these two were different. Can you confirm ?
1

[code]
$arr = array(“male”=>”NogDog”,”male”=>”Sempervivum”)
[/code]

2

[code]
$arr = array(“male=>NogDog”,”male=>Sempervivum”)
[/code]

In my test, the last one seem not to take into account the key since the “=>” is inside the quotes.
This one is way too wrong ? Right ?
Mistakenly I wrote it like that and then came to my sense somehow what I am doing wrong.
Array that has no key and just the value. What do you call them ? Just Index arrays ?

Anyway, reading upon dimensional arrays at w3schools.com.
Can you believe it, I still haven’t learnt about all array types and have already built membership PHP scripts (Login, Logout, Register, Google like SERP (pagination)).
Learnt $_SESSIONS, $_COOKIES, $_GET, $_POST, $_REQUEST, $_SERVER[‘REQUEST_METHOD’], $_SERVER[Php_SELF’], Prep Stmts and the like few yrs back and yet only been dealing with index type arrays these 4-5yrs with procedural style PHP. Lol!
But still consider myself a long time 4/5yrs beginner selfstudy student as I still haven’t fully got into Oop or even pdo which I consider intermediate level PHP.
Amazing hey ? Still a beginner level and yet managed to build my own membership site and Yahoo like Index. Gonna jump into building a web messenger like Watsup. Only thing I can’t program is voIP free video conferencing, video calling and the like. Gonna add my own unique features that Watsup doesn’t have. Added my own unique features on my SE that Google doesn’t have. Gonna add unique features on my Forum PHP too. I only build things if I comeup with my own unique features to standout from the crowd.
Once you people answer my other latest threads, I’d finish building my Google type bot and turn the online index into a Searchengine. Gonna build my own forum too and all with procedural style beginner level PHP. Yes, yes, adding dB security. Prepared Statements.So don’t worry about becoming SQL injection target at beginner level. Lol!
Try answering my other threads. Especially ones that deal with data extraction or manipulation.

I knew once I have learnt the basics of data dumping and extracting to/fro MySql dB (Insert, Delete, Update, Select) then I’d be able to build websites. Social Networks, Forums, etc.
Hence jumped straight into MySql whilst a beginner level student. Prep Stmts.
Next need to complete learning Mobile Friendly pages. CSS, I not caring too much. As building fancy pages ain’t that much of my target. That can come later. Right now, need to learn about data manipulation and array is my thing. Got to finish the array subject properly.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 12.2021 — Within a quoted string, => is just 2 random characters with no meaning, so in that case you are creating an enumerated array with two values that just happen to have those 2 characters in the middle of each.

But, when you use them as the operator that associates the array key to a value, you used the same key twice, so the 2nd assignment would overwrite the first. I'm guessing what you really wanted was something like:
<i>
</i>$arr = array(
array("name" =&gt; "nogdog", "gender" =&gt; "male"),
array("name" =&gt; "6op6ou", "gender" =&gt; "female")
);

var_export($arr);
// outputs:
// array (
// 0 =&gt;
// array (
// 'name' =&gt; 'nogdog',
// 'gender' =&gt; 'male',
// ),
// 1 =&gt;
// array (
// 'name' =&gt; '6op6ou',
// 'gender' =&gt; 'female',
// ),
// )
Copy linkTweet thisAlerts:
@developer_webauthorFeb 15.2021 — @NogDog#1627868

You are very right.
Copy linkTweet thisAlerts:
@viakgroupFeb 16.2021 — it's really very hard
Copy linkTweet thisAlerts:
@VITSUSAFeb 16.2021 — @developer_web#1627859 I agree with NogDog, in the quoted string, => is just 2 random characters with no meaning,
Copy linkTweet thisAlerts:
@developer_webauthorFeb 19.2021 — @viakgroup#1628031

What is hard ?
×

Success!

Help @developer_web 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 4.27,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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