一年没来,循例散分解决方案
一年没来,循例散分
照旧,发两个自用的“小”东西,给点改善意见的多些分,纯接分的巡查管理员应该会删贴的,嘿嘿
注:因为是自用,传入基本是格式正规的,所以没有做容错,这个用者自理
//搜索文件中的字串,返回所在行的行号
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $lines=new ArrayIterator(file(文件名)); $regex = 搜索用的正则; //必须是正则,因为下面的迭代器是正则迭代器 $regexFilter = new RegexIterator($lines, $regex, RegexIterator::GET_MATCH); $items = iterator_to_array($regexFilter); //其实上面这段东东还能更广泛应用,善用对处理大文件有很大帮助,自己去举一反三吧 $keys = array_keys($items); //如果你搜索的值不是唯一的,这里就是多个行号的数组(注意第一行是“0”) $lineNumber = $keys[0]; //如果你搜索的值是唯一的,这里就是你要的行号
//对行列(矩阵)数组交换一维和二维键
什么是矩阵数组,每一维键名存在且顺序是对应的二维数组,简单举例就是SQL后得到的二维数组,当然还有更多
注意是顺序对应,不然没有意义,两维都是数字键名也能用,但数字键名感觉也是意义不大,因为数字键名用交并差很方便的
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> 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); //这里本来想直接iterator_to_array省循环,但出错,不解 if (isset($array[0])) $arr = array_combine(array_keys($array[0]),$arr); return $arr; } } //类中只写了一个交换方法,有兴趣的人可以自行扩展
SPL代码很简洁,可惜文档太少了,很多都要自己写后测试看结果,累啊
------解决方案--------------------
是好久没来了,还以为你跳出苦海了呢
------解决方案--------------------
在沙发上迷糊一会~
------解决方案--------------------
过来加点人气
------解决方案--------------------
唉~~~~我这都为分少而蛋痛的不得了,楼主还挥分如土……技术烂伤不起啊~~~~~~~~~~
------解决方案--------------------
东西不错 搬个小板凳看
------解决方案--------------------
几小时没来 赶紧来接分 高呼代码共享万岁.
------解决方案--------------------
支持一个,都没有看到代码呢
------解决方案--------------------
接分积分,很久没来了
------解决方案--------------------
开源万岁~
------解决方案--------------------
谢谢楼主分享,坐等牛人的改进方案
------解决方案--------------------
悄悄的路过。。。支持。。。。。
------解决方案--------------------
过来加点人气
------解决方案--------------------
我党需要楼主这样的人才,入党吧。
------解决方案--------------------
ArrayIterator 是个高深的东西,文档太少,表示不解
------解决方案--------------------
小东西大用处,不懂PHP,学习来着,坐等高人
------解决方案--------------------
112341354354
------解决方案--------------------
我背着麻袋来接...
------解决方案--------------------
PHP貌似不是很难学......
------解决方案--------------------
PHP据说与c很像。。。
有机会可以学学。。
------解决方案--------------------
这个号不知道丢了多久了,上来冒个泡
------解决方案--------------------

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
