I haven't been here for a year. I just sent two "small" items for my own use and provided more points for improvement suggestions. the inspection administrator who just received the points should delete them. Hey, note: because it is for your own use, the input is basically in a regular format, so there is no fault tolerance. this user searches for strings in the file and returns the row number PHPcode $ linesnewArrayIterator (file name )); $ regex indicates the regular expression used for search. it must be a regular expression. it does not come for one year.
As usual, send two "small" items for your own use and give more points for improvement suggestions. the inspection administrator who only receives points should delete the posts.
Note: Because it is for your own use, the input is basically in a regular format, so there is no fault tolerance. This user takes care of it.
// Search for strings in the file and return the row number
PHP code
$ Lines = new ArrayIterator (file name); $ regex = regular expression used for search; // it must be a regular expression, because the following iterator is a regular iterator $ regexFilter = new RegexIterator ($ lines, $ regex, RegexIterator: GET_MATCH); $ items = iterator_to_array ($ regexFilter ); // In fact, the above section can be more widely used. it is of great help to make good use of large files. let's take a look at it by yourself $ keys = array_keys ($ items ); // if the search value is not unique, it is an array of multiple row numbers (note that the first row is "0") $ lineNumber = $ keys [0]; // if the value you search for is unique, here is the row number you want
// Exchange one-dimensional and two-dimensional keys for the row and column (matrix) arrays
What is a matrix array? each one-dimensional key name exists and the order is a two-dimensional array. A simple example is the two-dimensional array obtained after SQL. of course, there are more
Note that it is sequential correspondence, otherwise it does not make sense. both dimensions can also be used as the number key name, but it does not make sense because the number key name is easy to use.
PHP code
Class squareArray {public function swapRowCol ($ array) {$ mit = new MultipleIterator (MultipleIterator: MIT_KEYS_ASSOC); foreach ($ array as $ key => $ value) {$ temArr = new ArrayIterator ($ value); $ mit-> attachIterator ($ temArr, $ key) ;}$ arr = array (); foreach ($ mit as $ item) array_push ($ arr, $ item); // The iterator_to_array statement is used to save loops, but an error occurs. if (isset ($ array [0]) $ arr = array_combine (array_keys ($ array [0]), $ arr); return $ arr ;}// only one switching method is written in the class, if you are interested, you can expand it on your own.
SPL code is very concise, but it is a pity that there are too few documents. many of them have to write and test the results on their own. tired.
------ Solution --------------------
I have never been here for a long time. I thought you have jumped out of the bitter sea.
------ Solution --------------------
Confused on the sofa for a moment ~
------ Solution --------------------
More popularity
------ Solution --------------------
Alas ~~~~ I am suffering a lot of pain points, and the landlord is still moving to the ground ...... The technology is terrible ~~~~~~~~~~
------ Solution --------------------
Nice stuff, move a bench
------ Solution --------------------
A few hours ago, I had to hurry up and talk about code sharing.
------ Solution --------------------
One is supported and no code is visible.
------ Solution --------------------
Points, not long ago
------ Solution --------------------
Long live ~
------ Solution --------------------
Thank you for sharing your suggestions.
------ Solution --------------------
Quietly passing... Yes .....
------ Solution --------------------
More popularity
------ Solution --------------------
Our party needs talents like the landlord to join the party.
------ Solution --------------------
ArrayIterator is an advanced object. there are too few documents to explain.
------ Solution --------------------
Little things are easy to use. they don't know PHP, learn, sit down and wait for someone else.
------ Solution --------------------
112341354354
------ Solution --------------------
I carry a sack to pick it up...
------ Solution --------------------
PHP does not seem very difficult to learn ......
------ Solution --------------------
PHP is said to be very similar to c...
I have the opportunity to learn ..
------ Solution --------------------
I don't know how long it took to lose this number.
------ Solution --------------------