Computers, Programming
Yuav ua li cas puas PHP array?
Ib tug array yog ib tug qauv ntaub ntawv no hais tias tso cai ib zaug xwb qhov chaw khaws cov tej yam tseem ceeb uas yog yam hais txog qhov tib hom.
array hom
Nws muaj ob hom ntawm arrays, lawv txawv nyob rau hauv txoj kev ntawm qhia kom paub txog cov constituent ntsiab.
- Tej yam yooj yim - txhua lub caij ntawd yog muab ib tug Performance index rau hauv ib tug ib theem zuj zus.
- Sib koom ua ke - nws muaj rau xa mus rau ib tug lub caij siv cov yuam sij txuam nrog cov zajlus kom qhov tseem ceeb.
Nyob rau hauv tej yam yooj yim cov ntsiab lus, nws yog ib tug nce mus nce los, uas yuav ua tau ntau tshaj ib qho. Peb txaus siab nyob rau hauv PHP array.
yam ntxwv nta
Xav txog PHP array cov ntsiab lus:
- Nws yuav muaj tej xov tooj ntawm qhov tseem ceeb, thiab nws yog tas.
- Txhua lub qhov tseem ceeb, uas muaj ib tug array ntawm PHP, hu ua lub caij.
- Caij khw muag khoom sib txawv ntawm cov tsiaj ntawv. Cov no yuav cov hlua, zauv, booleans.
- Mus saib tau lub ntsiab yog tau siv indexes uas yog nyob rau hauv lowercase thiab numeric.
- PHP array muaj ntsiab nrog nws indexes.
- Cov nab npawb ntawm cov ntsiab nyob rau hauv lub array - yog nws kav ntev npaum.
- Qhov tseem ceeb ntawm lub ntsiab kuj yuav arrays, raws li yog multi-dimensional arrays.
Ib tug txawv feature ntawm PHP yog lub peev xwm los tsim ib qho array nyob rau hauv tsab ntawv ntawm tej complexity.
Zoo:
- Nws yog ib qho yooj yim mus ua hauj lwm ib txhij nrog ntau yam tseem ceeb nyob rau hauv ib tug array. Nws yog ib qho yooj yim mus ua ib lub voj voog nyob rau hauv nws cov tswv cuab los mus hloov qhov tseem ceeb.
- Lawv yog cov yooj yim mus muab. Cias tshem tawm, ntxiv khoom rau nyeem los yog hloov qhov tseem ceeb ntawm lub ntsiab.
- Nyob rau hauv PHP, muaj ntau ntau yam sib txawv zog uas tso cai rau koj mus daws cov arrays. Muaj ib tug nrhiav rau tej qhov tseem ceeb, sorting, phiajcim arrays.
hom
Arrays raug muab faib ntxiv mus rau hauv 2 hom:
- ib-seem;
- ob-seem.
Muaj ntau txoj kev rau initialize tus array. Ua ntej, xav txog tej yam yooj yim, thiab ces - ib tug associative array PHP.
QAUV tsim ib tug yooj yim array nyob rau hauv PHP:
Muab ib tug PHP array caij qhov tseem ceeb yuav tsum muab sau raws li:
- $ Array [n] = z;
- n - qhov tseem ceeb, z - tus nqi.
Nyob rau hauv lub thib ob hom ntawm initialization yuav ua tau tsis muaj dab tsi yuav qhia tau nyob rau hauv pab pawg :
- $ Npe [] = "ib tug";
- $ Npe [] = "ob";
- $ Npe [] = "peb".
Nyob rau hauv cov ntaub ntawv no, lub Performance index yuav sib npaug zos rau lub neej ntawd: 0, 1 thiab 2.
Thiab koj muaj peev xwm muab tej yam nws Performance index nqi:
- $ Npe [35] = 'ib';
- $ Npe [18] = 'ob';
- $ Npe [90] = "peb".
Koj yuav muab cov initialization txoj kev:
- $ Npe [37] = "thawj";
- $ Npe [5] = "thib ob";
- $ Npe [] = "peb".
Qhov thib peb lub caij yog muab rau ib tug Performance index sib npaug zos rau 38, raws li 37 - qhov loj tshaj plaws ntawm lub indexes.
Multidimensional array syntax zoo li no:
$ Npe [indeks1] [indeks2] ....
Tam sim no cia saib dab tsi ib tug PHP associative array. Qhov Performance index yuav ua tau ib txoj hlua, nws tsis muaj cai yuam kom txwv, tej qhov chaw muaj cai, nws kav ntev npaum no sib txawv. Sib koom ua ke arrays zoo siv thaum nws yog tsim nyog los txuas lub ntsiab yeej tsis nrog cov xov tooj, tab sis cov lus. Arrays uas muaj indexes - cov hlua yog hu ua associative.
Nyob rau hauv ib-seem associative arrays muaj tsuas yog ib qhov tseem ceeb, nws raws li ib tug Performance index. Cov duab saum toj no yog ib qho piv txwv ntawm ib tug-dimensional thiab multi-dimensional associative arrays.
Koj muaj peev xwm tsim ib tug ntau txoj associative array nyob rau hauv lub classical txoj kev, tab sis nws tsis yog yooj yim heev.
Similar articles
Trending Now