A year has not come, by example scattered

Source: Internet
Author: User
As usual, two for personal use of "small" things, to point to improve the opinion of more points, pure access to the inspection manager should be deleted paste, hey
Note: Because it is for personal use, the incoming basic is formal format, so did not do fault tolerance, this user self-

Searches for a string in a file, returning the line number of the row
$lines =new arrayiterator (file (filename)); $regex = regular for searching;  Must be regular because the following iterator is a regular iterator $regexfilter = new Regexiterator ($lines, $regex, regexiterator::get_match); $items = iterator_to _array ($regexFilter);//actually above this section can be more widely used, the use of large files to deal with a lot of help, go extrapolate it $keys = Array_keys ($items);  If the value you are searching for is not unique, here is an array of multiple line numbers (note that the first line is "0") $lineNumber = $keys [0];  If the value you are searching for is unique, here is the line number you want


Array-to-row (matrix) arrays Exchange one-and two-dimensional keys
What is a matrix array, each key name exists and the order is the corresponding two-dimensional array, a simple example is SQL after the two-dimensional array, of course, there are more
Note is the order corresponds, otherwise there is no meaning, two-dimensional is the number of key names can also be used, but the number of key names feel is not very significant, because the number of key names with orthogonal poor very convenient
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); This would have been a direct iterator_to_array of the province, but it went wrong, puzzled if (isset ($array [0])) $arr = Array_combine (Array_keys ($array [0]), $arr); return $ arr;}} Only one Exchange method is written in the class, and interested people can extend their own


SPL code is very concise, but too few documents, many of them have to write their own test to see the results, tired AH


Reply to discussion (solution)

It's been a long time since I thought you jumped out of your misery.

On the couch, confused for a while

Come on, spice up.

Oh ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ I am a little and the egg is sore, the landlord is still like Earth ... Technology sucks, ~~~~~~~~~~.

Nice move, a little bench look.

I haven't been here in a couple of hours. Shouting code share Viva.

Support One, and you don't see the code.

Score points, it's been a long time.

Open Source Long Live ~

Thank you landlord to share, waiting for the improvement of the cattle people plan

Quietly passing by ... Support.....

Come on, spice up.

It's been a long time since I thought you jumped out of your misery.

Jumped out of the misery, but fell into the fire pit ... Alas, struggle ... To struggle again ... On the shore--swamp!

Our party needs such talents as the landlord.

Arrayiterator is a very advanced thing, the document is too small to express the puzzled


Small things big use, do not understand PHP, study, wait for high man

112341354354

I'm carrying a sack to pick up ...

PHP seems to be not very difficult to learn ...

PHP is said to be like C ...
Have the opportunity to learn.

This number doesn't know how long it's been lost, come up and take a bubble

Ok!

It means I can't read.

Well, don't understand, wait downstairs to fight to save ~

Yes, LZ mighty.

If you want to scatter, I'm going to pick it up!

Good thing, thanks. Can a novice be a little more scattered

First of all, I say support.

Novice drifting over, learn less to say.

$lines =new arrayiterator (file (filename));
$regex = regular for searching; Must be regular because the following iterator is a regular iterator
$regexFilter = new Regexiterator ($lines, $regex, Regexiterator::get_match);
$items = Iterator_to_array ($regexFilter);
In fact, this part of the above can be more widely used, the use of large files to deal with a lot of help, go to extrapolate yourself

$keys = Array_keys ($items); If the value you are searching for is not unique, here is an array of multiple line numbers (note that the first line is "0")
$lineNumber = $keys [0]; If the value you are searching for is unique, here is the line number you want http://www.jianfeimb.com/special/

Do not know the landlord classmate

Not PHP, onlookers landlord scattered points

Access points

Not PHP, onlookers landlord scattered points

Onlookers

  • 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.