I haven't been here for a year. what should I do if I just split my score?

Source: Internet
Author: User
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 takes care of/search for strings in the file, return the row number $ lines = new & nbsp; array has not arrived in a year, and the samples are scattered.
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

$ 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 it to process large files. let's just put it apart.

$ Keys = array_keys ($ items); // if the value you search for 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, this 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.

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 );
If (isset ($ array [0]) $ arr = array_combine (array_keys ($ array [0]), $ arr );
Return $ arr;
}
}
// Only one exchange 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 --------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.