The php array gets all the elements before a value

problem description

$data=array (
  1 => "8",
  2 => "56",
  3 => "64",
  4 => "90",
  5 => "11",
  6 => "32",
  7 => "30",
  8 => "90",
)

how to get the key value of $data is 11, put all the previous key values into a new array, and put all the key values after the key value of 11 into a new array

what result do you expect?

is there an easy way to get it? but I can only use for plus a count statistic and then subtract.

Nov.24,2021

to give a reference to the idea, the original array is directly transformed into a JSON string, because you have a key value, so you can basically reverse the content except the key name, and then find and separate out two substrings (at the same time do some small processing to make them legal JSON), and then restore the memory data respectively.


array_search search 11 after getting the index, use array_slice to cut the array.


read more about the document series
array_ searching
array_slice

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bcba65-30ab0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bcba65-30ab0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?