Working with an array – PHP – SitePoint Forums

[ad_1]

I have

Array
(
[0] => Array
(
[beginning_ru] => 33.0
[ending_ru] => 33.5
[beginning_x] => 0.0
[external_width] => 17.500
[external_height] => 0.500
[rack_mounting_direction] => Front
[operational_status] => 1
)

[1] => Array
(
[beginning_ru] => 27.0
[ending_ru] => 30.0
[beginning_x] => 0.0
[external_width] => 17.500
[external_height] => 1.750
[rack_mounting_direction] => Front
[operational_status] => 1
)

)

am trying to create a new array from it using only the begining_ru and ending_ru keys.
like

Array
(
[0] => Array
(
[beginning_ru] => 33.0
[ending_ru] => 33.5
)

[1] => Array
(
[beginning_ru] => 27.0
[ending_ru] => 30.0
)

)

rpkamp

January 8, 2023, 10:03am
#2

Why? Can’t you just ignore all keys you don’t need?

5 Likes

Unless you’re pulling absolutely massive amounts of records (where size-in-memory becomes a concern), @rpkamp is 100% correct, there’s no mechanical benefit to doing this.

2 Likes

What if he wants to save the array as JSON and does not need the other data?

your right, ill use the existing array and ignore the other keys.

1 Like

the second one seems good
I want the function to run when a form is…

..

[ad_2]

Read More

About the author

Working with an array – PHP – SitePoint Forums – webhostingreviewsite.com