PHP学习系列7
PHP学习系列七
数据库操作
数组:
$product = array('tires','oil','spark plugs');
array是一个语言结构,而不是函数。
$product[0],$product[1]
foreach($produce as $current){
echo $current." ";
}
关联数组:
$prices=array('Tires'=>100,'oil'=>10,'spark plugs'=>4)
访问:$prices['Tires']
遍历:foreach或list()和each()结构
foreach($prices as $key => $value){
echo $key." - ".$value."
";
}
while($element = each($prices)){
echo $element['key'];
echo "-";
echo $element['value'];
echo "
";
}
while(list($product,$price) = each($prices)){
echo "$product-$price
";
}
list()将从each()返回的数组中所包含0,1两个元素变成为两个名为$product和$price的新变量。
如果希望在相同脚本中两次使用该数组,就必须使用函数reset()将当前元素重新设置到数组开始处。再次遍历,使用如下:
reset($prices);
while(list($product,$price)=each($prices)){
echo "$produce - $price
";
}
sort():数组排序.区分大小写。大写字母都在小写字母前面。
asort()
ksort():对关联数组排序。
asort()根据每个元素值排序。ksort()按关键字排序。
反向排序:rsort(),arsort(),krsort().
使用usort()告诉php如何比较各个元素,需要编写自己的比较函数。相当与java中实现compareTo()函数。
function compare($x,$y){
if($x[1] == $y[1]){
return 0;
}else if($x[1] return -1;
}else{
return 1;
}
}
usort($product,'compare');
如果要让数组按另一种顺序存储,只要编写一个不同的比较函数。
uasort(),uksort()

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

AI Hentai Generator
Generate AI Hentai for free.

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



Fujifilm fans were recently very excited at the prospect of the X-T50, since it presented a relaunch of the budget-oriented Fujifilm X-T30 II that had become quite popular in the sub-$1,000 APS-C category. Unfortunately, as the Fujifilm X-T50's launc

TheFiiOCP13cassetteplayerwasannouncedinJanuary.Now,FiiOisexpandingitsportfoliowithtwonewmodels-onewitharedfrontandonewithatransparentfront.Thelatternotonlyperfectlymatchestheretrocharmoftheangulardesign,butalso

The Klipsch Flexus Core 300 is the top model in the series and is positioned above the already available Flexus Core 200 in the company's soundbar line-up. According to Klipsch, this is the first soundbar in the world whose sound can be adapted to th

WhiletheLightPhone2from2018wasstillequippedwithaneconomicale-inkdisplay,theLightPhone3usesanOLEDdisplaythatcanonlydisplaygrayscale.Thereasonfortheswitchtothe3.92-inchOLEDpanelwithitsresolutionof1,240x1,080isth

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Shortly after Tesla launched the Model 3 Highland refresh towards the end of last year, the US federal EV tax incentive rules changed, cutting the potential discount in half for eligible buyers because of Tesla's use of Chinese LFP cells in the new M

With the development of the Internet and the advancement of information technology, the era of big data has arrived, and fields such as data analysis and machine learning have also been widely used. In these fields, task scheduling is an inevitable problem. How to achieve efficient task scheduling is crucial to improving efficiency. In this article, we will introduce how to use Golang's web framework Echo framework to implement distributed task scheduling. 1. Introduction to the Echo framework Echo is a high-performance, scalable, lightweight GoWeb framework. It is based on HTTP
