Skip to content

array_unshift page, add an example with two associative arrays#1954

Merged
tiffany-taylor merged 3 commits intophp:masterfrom
tiffany-taylor:array-unshift-example
Dec 17, 2022
Merged

array_unshift page, add an example with two associative arrays#1954
tiffany-taylor merged 3 commits intophp:masterfrom
tiffany-taylor:array-unshift-example

Conversation

@tiffany-taylor
Copy link
Copy Markdown
Member

@tiffany-taylor tiffany-taylor commented Nov 5, 2022

Added an example that shows how two associative arrays are combined using array_unshift()

https://www.php.net/manual/en/function.array-unshift.php

@tiffany-taylor
Copy link
Copy Markdown
Member Author

tiffany-taylor commented Nov 5, 2022

Gah, need to fix the spacing on <![CDATA[, didn't mean to alter that.
Fixed.

@tiffany-taylor
Copy link
Copy Markdown
Member Author

Converting this to draft so that I can provide a better example.

@tiffany-taylor tiffany-taylor marked this pull request as draft November 7, 2022 01:58
@cmb69
Copy link
Copy Markdown
Member

cmb69 commented Nov 7, 2022

I suggest not to think of "multi-dimensional" arrays in PHP; that eases the understanding how these are handled by language constructs and functions.

That said, I'm not against adding such an example for array_unshift(), since almost everybody talks about "multi-dimensional" PHP arrays.

@tiffany-taylor
Copy link
Copy Markdown
Member Author

TFW I realize I meant to call it "associative" and not "multi-dimensional" 😆

@tiffany-taylor tiffany-taylor changed the title array_unshift page, add an example with two multidimensional arrays array_unshift page, add an example with two associative arrays Nov 9, 2022
@tiffany-taylor
Copy link
Copy Markdown
Member Author

check-whitespace fails on a line that I fixed in the latest commit. It appears the job is looking at an older commit where the trailing whitespace was present. I'm not sure if the current failed job is a false-positive, or something I need to resolve.

@cmb69
Copy link
Copy Markdown
Member

cmb69 commented Nov 9, 2022

@tiffany-taylor, to make the white-space-checker happy, you need to squash the commits, and force-push.

…evise wording, add types of fruits and vegetables into second example

Re: wording revisions: it's an associative array, not a multi-dimensional array, Past Tiffany. 🤦
@tiffany-taylor tiffany-taylor marked this pull request as ready for review November 9, 2022 20:38
Comment on lines +116 to +120
<title>Usage with associative arrays</title>
<para>
If one associative array is prepended to another associative array,
the prepended array is numerically indexed into the former array.
</para>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add array_merge() to the See Also, and maybe a note somehow that maybe the function wanted is that one?

Copy link
Copy Markdown
Member Author

@tiffany-taylor tiffany-taylor Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with array_merge being the wanted one. I think there will be cases that people will want array_unshift, but this will likely be situations where people have a stronger grasp of the array_* functions.

@tiffany-taylor tiffany-taylor merged commit caf7791 into php:master Dec 17, 2022
claudepache pushed a commit to claudepache/php-doc-en that referenced this pull request Jun 1, 2023
…#1954)

* Add an example showing how two associative arrays are combined

* Modernize array syntax in first example, use var_dump over print_r, revise wording, add types of fruits and vegetables into second example

* Add `array_merge()` to the "See Also" section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants