216.73.216.34 TODAY : 208

PHP ์˜จ๋ผ์ธ ๊ฐ•์˜

 > 

PHP - ์ดˆ๊ธ‰

๐Ÿ“š PHP ์ดˆ๊ธ‰ - 6์ฃผ์ฐจ: ๋ฐฐ์—ด - 03 ๋‹ค์ฐจ์› ๋ฐฐ์—ด

๐Ÿ“š PHP ์ดˆ๊ธ‰ - 6์ฃผ์ฐจ: ๋ฐฐ์—ด - 03 ๋‹ค์ฐจ์› ๋ฐฐ์—ด
ํ‰์  10.0 ๋ผ์ด์„ผ์Šค free
์‚ฌ์šฉ์žํ‰์  10.0 ์šด์˜์ฒด์ œ
๋‹ค์šด๋กœ๋“œ 1 ํŒŒ์ผํฌ๊ธฐ 0
์ œ์ž‘์‚ฌ LUZENSOFT ๋“ฑ๋ก์ผ 2025-06-30 17:24:30
์กฐํšŒ์ˆ˜ 49
- ์„ค๋ช…

๐Ÿ“š PHP ์ดˆ๊ธ‰ - 6์ฃผ์ฐจ: ๋ฐฐ์—ด - 04 ๋ฐฐ์—ด ์กฐ์ž‘ ํ•จ์ˆ˜ (์ •๋ ฌ, ์ถ”๊ฐ€/์‚ญ์ œ ๋“ฑ)





์•ˆ๋…•ํ•˜์„ธ์š”! #PHP ์ดˆ๊ธ‰ ๊ฐ•์ขŒ 6์ฃผ์ฐจ์˜ ๋งˆ์ง€๋ง‰ ์‹œ๊ฐ„์ž…๋‹ˆ๋‹ค. ์ง€๋‚œ ์‹œ๊ฐ„์—๋Š” #PHP #๋ฐฐ์—ด ์˜ ๊ฐ•๋ ฅํ•œ ๊ธฐ๋Šฅ์ธ #๋‹ค์ฐจ์›๋ฐฐ์—ด ์— ๋Œ€ํ•ด ํ•™์Šตํ–ˆ๋Š”๋ฐ์š”. ์˜ค๋Š˜์€ PHP ๋ฐฐ์—ด์„ ๋” ํšจ์œจ์ ์œผ๋กœ ๋‹ค๋ฃจ๊ณ  ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š” ๋‹ค์–‘ํ•œ ๋ฐฐ์—ด ์กฐ์ž‘ ํ•จ์ˆ˜๋“ค์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฐฐ์—ด์„ ์ •๋ ฌํ•˜๊ฑฐ๋‚˜, ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ ๋ฐ ์‚ญ์ œํ•˜๋Š” ๋“ฑ ์‹ค์ „์—์„œ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ํ•„์ˆ˜ ํ•จ์ˆ˜๋“ค์„ ํ•จ๊ป˜ ์‚ดํŽด๋ณด์‹œ์ฃ !





1. ๋ฐฐ์—ด ์ •๋ ฌ ํ•จ์ˆ˜

uploadImage


PHP๋Š” ๋ฐฐ์—ด์„ ๋‹ค์–‘ํ•œ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•  ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ฃผ๋กœ ๊ฐ’ ๋˜๋Š” ํ‚ค๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ/๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ์„ ํ•ฉ๋‹ˆ๋‹ค.




1.1. ๊ฐ’(Value)์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ


  • sort(): ๋ฐฐ์—ด์˜ ๊ฐ’์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. ์ธ๋ฑ์Šค ๋ฐฐ์—ด์˜ ํ‚ค๋Š” ์žฌ์„ค์ •(0๋ถ€ํ„ฐ ์ˆœ์ฐจ์ ์œผ๋กœ)๋ฉ๋‹ˆ๋‹ค.

  • rsort(): ๋ฐฐ์—ด์˜ ๊ฐ’์„ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. ์ธ๋ฑ์Šค ๋ฐฐ์—ด์˜ ํ‚ค๋Š” ์žฌ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

PHP

<?php
$numbers = [4, 2, 8, 1, 5];
$fruits = ["orange", "banana", "apple", "grape"];

echo "<h3>๊ฐ’ ๊ธฐ์ค€ ์ •๋ ฌ</h3>";

// sort() - ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
sort($numbers);
echo "sort() ํ›„ numbers: ";
print_r($numbers); // Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 8 )
echo "<br>";

sort($fruits);
echo "sort() ํ›„ fruits: ";
print_r($fruits); // Array ( [0] => apple [1] => banana [2] => grape [3] => orange )
echo "<br><br>";

// rsort() - ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
rsort($numbers);
echo "rsort() ํ›„ numbers: ";
print_r($numbers); // Array ( [0] => 8 [1] => 5 [2] => 4 [3] => 2 [4] => 1 )
echo "<br>";

rsort($fruits);
echo "rsort() ํ›„ fruits: ";
print_r($fruits); // Array ( [0] => orange [1] => grape [2] => banana [3] => apple )
echo "<br>";
?>




1.2. ํ‚ค(Key)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ


  • ksort(): ๋ฐฐ์—ด์˜ ํ‚ค๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. (์—ฐ๊ด€ ๋ฐฐ์—ด์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ)

  • krsort(): ๋ฐฐ์—ด์˜ ํ‚ค๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ฉ๋‹ˆ๋‹ค. (์—ฐ๊ด€ ๋ฐฐ์—ด์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ)

PHP

<?php
$age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];

echo "<h3>ํ‚ค ๊ธฐ์ค€ ์ •๋ ฌ</h3>";

// ksort() - ํ‚ค ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
ksort($age);
echo "ksort() ํ›„ age: ";
print_r($age); // Array ( [Ben] => 37 [Joe] => 43 [Peter] => 35 )
echo "<br><br>";

// krsort() - ํ‚ค ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
krsort($age);
echo "krsort() ํ›„ age: ";
print_r($age); // Array ( [Peter] => 35 [Joe] => 43 [Ben] => 37 )
echo "<br>";
?>




1.3. ๊ฐ’(Value)์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•˜๋˜ ํ‚ค(Key) ์œ ์ง€


  • asort(): ๋ฐฐ์—ด์˜ ๊ฐ’์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋˜, ํ•ด๋‹น ๊ฐ’๊ณผ ์—ฐ๊ฒฐ๋œ ํ‚ค๋ฅผ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. (์—ฐ๊ด€ ๋ฐฐ์—ด์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ)

  • arsort(): ๋ฐฐ์—ด์˜ ๊ฐ’์„ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋˜, ํ•ด๋‹น ๊ฐ’๊ณผ ์—ฐ๊ฒฐ๋œ ํ‚ค๋ฅผ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. (์—ฐ๊ด€ ๋ฐฐ์—ด์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ)

PHP

<?php
$age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];

echo "<h3>๊ฐ’ ๊ธฐ์ค€ ์ •๋ ฌ (ํ‚ค ์œ ์ง€)</h3>";

// asort() - ๊ฐ’ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ, ํ‚ค ์œ ์ง€
asort($age);
echo "asort() ํ›„ age: ";
print_r($age); // Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
echo "<br><br>";

// arsort() - ๊ฐ’ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ, ํ‚ค ์œ ์ง€
arsort($age);
echo "arsort() ํ›„ age: ";
print_r($age); // Array ( [Joe] => 43 [Ben] => 37 [Peter] => 35 )
echo "<br>";
?>





2. ๋ฐฐ์—ด ์š”์†Œ ์ถ”๊ฐ€ ๋ฐ ์‚ญ์ œ ํ•จ์ˆ˜

uploadImage

๋ฐฐ์—ด์— ์ƒˆ๋กœ์šด ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜, ๊ธฐ์กด ์š”์†Œ๋ฅผ ์‚ญ์ œํ•˜๋Š” ๋‹ค์–‘ํ•œ ํ•จ์ˆ˜๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.




2.1. ์š”์†Œ ์ถ”๊ฐ€


  • array_push(): ๋ฐฐ์—ด์˜ ๋์— ํ•˜๋‚˜ ์ด์ƒ์˜ ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. (์ธ๋ฑ์Šค ๋ฐฐ์—ด์— ์œ ์šฉ)

  • array_unshift(): ๋ฐฐ์—ด์˜ ๋งจ ์•ž์— ํ•˜๋‚˜ ์ด์ƒ์˜ ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ์กด ์š”์†Œ๋“ค์˜ ํ‚ค๊ฐ€ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.

PHP

<?php
$fruits = ["apple", "banana"];

echo "<h3>์š”์†Œ ์ถ”๊ฐ€</h3>";

// array_push() - ๋ฐฐ์—ด ๋์— ์ถ”๊ฐ€
array_push($fruits, "cherry", "mango");
echo "array_push() ํ›„ fruits: ";
print_r($fruits); // Array ( [0] => apple [1] => banana [2] => cherry [3] => mango )
echo "<br><br>";

// array_unshift() - ๋ฐฐ์—ด ๋งจ ์•ž์— ์ถ”๊ฐ€
$colors = ["red", "blue"];
array_unshift($colors, "green", "yellow");
echo "array_unshift() ํ›„ colors: ";
print_r($colors); // Array ( [0] => green [1] => yellow [2] => red [3] => blue )
echo "<br>";
?>




2.2. ์š”์†Œ ์‚ญ์ œ


  • array_pop(): ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  • array_shift(): ๋ฐฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ์กด ์š”์†Œ๋“ค์˜ ํ‚ค๊ฐ€ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.

  • unset(): ํŠน์ • ํ‚ค/์ธ๋ฑ์Šค์˜ ์š”์†Œ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. ํ‚ค๋Š” ์žฌ์„ค์ •๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

PHP

<?php
$stack = ["a", "b", "c", "d"];

echo "<h3>์š”์†Œ ์‚ญ์ œ</h3>";

// array_pop() - ๋งˆ์ง€๋ง‰ ์š”์†Œ ์‚ญ์ œ
$lastElement = array_pop($stack);
echo "array_pop()์œผ๋กœ ์‚ญ์ œ๋œ ์š”์†Œ: " . $lastElement . "<br>"; // d
echo "array_pop() ํ›„ stack: ";
print_r($stack); // Array ( [0] => a [1] => b [2] => c )
echo "<br><br>";

// array_shift() - ์ฒซ ๋ฒˆ์งธ ์š”์†Œ ์‚ญ์ œ
$firstElement = array_shift($stack);
echo "array_shift()์œผ๋กœ ์‚ญ์ œ๋œ ์š”์†Œ: " . $firstElement . "<br>"; // a
echo "array_shift() ํ›„ stack: ";
print_r($stack); // Array ( [0] => b [1] => c )
echo "<br><br>";

// unset() - ํŠน์ • ํ‚ค/์ธ๋ฑ์Šค ์š”์†Œ ์‚ญ์ œ
$data = ["name" => "Alice", "age" => 30, "city" => "Seoul"];
unset($data["age"]);
echo "unset() ํ›„ data (age ์‚ญ์ œ): ";
print_r($data); // Array ( [name] => Alice [city] => Seoul )
echo "<br><br>";

$list = ["apple", "banana", "cherry"];
unset($list[1]); // ์ธ๋ฑ์Šค 1 ์‚ญ์ œ
echo "unset() ํ›„ list (์ธ๋ฑ์Šค 1 ์‚ญ์ œ): ";
print_r($list); // Array ( [0] => apple [2] => cherry ) -> ์ธ๋ฑ์Šค ์žฌ์„ค์ • ์•ˆ ๋จ!
echo "<br>";
?>





3. ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ ๋ฐ ๋ถ„ํ•  ํ•จ์ˆ˜


๋ฐฐ์—ด์„ ํ•ฉ์น˜๊ฑฐ๋‚˜ ํŠน์ • ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜๋“ค๋„ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.


uploadImage


3.1. ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ


  • array_merge(): ํ•˜๋‚˜ ์ด์ƒ์˜ ๋ฐฐ์—ด์„ ํ•ฉ์ณ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ํ‚ค๊ฐ€ ์ˆซ์ž์ด๋ฉด ์žฌ์„ค์ •๋˜๊ณ , ๋ฌธ์ž์—ด ํ‚ค๋Š” ๋™์ผํ•˜๋ฉด ๋‚˜์ค‘์— ์˜จ ๊ฐ’์œผ๋กœ ๋ฎ์–ด์”๋‹ˆ๋‹ค.

  • + (๋ฐฐ์—ด ๊ฒฐํ•ฉ ์—ฐ์‚ฐ์ž): ๋‘ ๋ฐฐ์—ด์„ ํ•ฉ์นฉ๋‹ˆ๋‹ค. ํ‚ค๊ฐ€ ๋™์ผํ•˜๋ฉด ๋จผ์ € ์˜จ ๋ฐฐ์—ด์˜ ๊ฐ’์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. (์—ฐ๊ด€ ๋ฐฐ์—ด์— ์œ ์šฉ)

PHP

<?php
$array1 = ["red", "green"];
$array2 = ["blue", "yellow"];
$array3 = ["color1" => "red", "color2" => "green"];
$array4 = ["color2" => "blue", "color3" => "yellow"];

echo "<h3>๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ</h3>";

// array_merge() - ์ธ๋ฑ์Šค ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ (ํ‚ค ์žฌ์„ค์ •)
$mergedArray1 = array_merge($array1, $array2);
echo "array_merge() ์ธ๋ฑ์Šค ๋ฐฐ์—ด: ";
print_r($mergedArray1); // Array ( [0] => red [1] => green [2] => blue [3] => yellow )
echo "<br><br>";

// array_merge() - ์—ฐ๊ด€ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ (ํ‚ค ์ค‘๋ณต ์‹œ ๋ฎ์–ด์“ฐ๊ธฐ)
$mergedArray2 = array_merge($array3, $array4);
echo "array_merge() ์—ฐ๊ด€ ๋ฐฐ์—ด: ";
print_r($mergedArray2); // Array ( [color1] => red [color2] => blue [color3] => yellow )
echo "<br><br>";

// + ์—ฐ์‚ฐ์ž - ์—ฐ๊ด€ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ (ํ‚ค ์ค‘๋ณต ์‹œ ๊ธฐ์กด ๊ฐ’ ์œ ์ง€)
$combinedArray = $array3 + $array4;
echo "+ ์—ฐ์‚ฐ์ž ์—ฐ๊ด€ ๋ฐฐ์—ด: ";
print_r($combinedArray); // Array ( [color1] => red [color2] => green [color3] => yellow )
echo "<br>";
?>




3.2. ๋ฐฐ์—ด ๋ถ„ํ• 


  • array_slice(): ๋ฐฐ์—ด์˜ ํŠน์ • ๋ถ€๋ถ„์„ ์ž˜๋ผ๋‚ด์–ด ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์›๋ณธ ๋ฐฐ์—ด์€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

PHP

<?php
$numbers = [10, 20, 30, 40, 50, 60];

echo "<h3>๋ฐฐ์—ด ๋ถ„ํ• </h3>";

// ์ธ๋ฑ์Šค 2๋ถ€ํ„ฐ 3๊ฐœ ์š”์†Œ ์Šฌ๋ผ์ด์Šค
$slice1 = array_slice($numbers, 2, 3);
echo "array_slice(2, 3) ํ›„: ";
print_r($slice1); // Array ( [0] => 30 [1] => 40 [2] => 50 )
echo "<br><br>";

// ์ธ๋ฑ์Šค -3๋ถ€ํ„ฐ ๋๊นŒ์ง€ ์Šฌ๋ผ์ด์Šค (๋’ค์—์„œ 3๋ฒˆ์งธ๋ถ€ํ„ฐ)
$slice2 = array_slice($numbers, -3);
echo "array_slice(-3) ํ›„: ";
print_r($slice2); // Array ( [0] => 40 [1] => 50 [2] => 60 )
echo "<br>";
?>





4. ๊ธฐํƒ€ ์œ ์šฉํ•œ ๋ฐฐ์—ด ํ•จ์ˆ˜


  • count(): ๋ฐฐ์—ด์˜ ์š”์†Œ ๊ฐœ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  • in_array(): ๋ฐฐ์—ด ์•ˆ์— ํŠน์ • ๊ฐ’์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

  • array_keys(): ๋ฐฐ์—ด์˜ ๋ชจ๋“  ํ‚ค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  • array_values(): ๋ฐฐ์—ด์˜ ๋ชจ๋“  ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  • array_unique(): ๋ฐฐ์—ด์—์„œ ์ค‘๋ณต๋œ ๊ฐ’์„ ์ œ๊ฑฐํ•˜๊ณ  ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  • array_reverse(): ๋ฐฐ์—ด์˜ ์š”์†Œ ์ˆœ์„œ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๋ฐ”๊พผ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.


    uploadImage

PHP

<?php
$data = ["apple", "banana", "apple", "cherry", "banana"];
$user_info = ["name" => "John", "age" => 30, "city" => "New York"];

echo "<h3>๊ธฐํƒ€ ์œ ์šฉํ•œ ํ•จ์ˆ˜</h3>";

// count()
echo "data ๋ฐฐ์—ด์˜ ์š”์†Œ ๊ฐœ์ˆ˜: " . count($data) . "<br>"; // 5
echo "<br>";

// in_array()
if (in_array("banana", $data)) {
    echo "data ๋ฐฐ์—ด์— 'banana'๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.<br>";
}
if (!in_array("grape", $data)) {
    echo "data ๋ฐฐ์—ด์— 'grape'๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.<br>";
}
echo "<br>";

// array_keys()
echo "user_info ๋ฐฐ์—ด์˜ ํ‚ค: ";
print_r(array_keys($user_info)); // Array ( [0] => name [1] => age [2] => city )
echo "<br><br>";

// array_values()
echo "user_info ๋ฐฐ์—ด์˜ ๊ฐ’: ";
print_r(array_values($user_info)); // Array ( [0] => John [1] => 30 [2] => New York )
echo "<br><br>";

// array_unique()
$uniqueData = array_unique($data);
echo "array_unique() ํ›„ data: ";
print_r($uniqueData); // Array ( [0] => apple [1] => banana [3] => cherry )
echo "<br><br>";

// array_reverse()
$reversedData = array_reverse($data);
echo "array_reverse() ํ›„ data: ";
print_r($reversedData); // Array ( [0] => banana [1] => cherry [2] => apple [3] => banana [4] => apple )
echo "<br>";
?>





๊ฒฐ๋ก 


์ด๋ฒˆ #PHP ์ดˆ๊ธ‰ ๊ฐ•์ขŒ์—์„œ๋Š” #PHP๋ฐฐ์—ด ์„ ํšจ์œจ์ ์œผ๋กœ ๋‹ค๋ฃจ๊ธฐ ์œ„ํ•œ ๋‹ค์–‘ํ•œ #๋ฐฐ์—ด์กฐ์ž‘ํ•จ์ˆ˜ ๋“ค์„ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

#์ •๋ ฌํ•จ์ˆ˜ (sort, rsort, ksort, krsort, asort, arsort)๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์›ํ•˜๋Š” ์ˆœ์„œ๋กœ ์ •๋ ฌํ•˜๊ณ , #์š”์†Œ์ถ”๊ฐ€ํ•จ์ˆ˜ (array_push, array_unshift)์™€ #์š”์†Œ์‚ญ์ œํ•จ์ˆ˜ (array_pop, array_shift, unset)๋ฅผ ์ด์šฉํ•ด ๋ฐฐ์—ด์˜ ๋‚ด์šฉ์„ ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์› ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ #๋ฐฐ์—ดํ•ฉ์น˜๊ธฐํ•จ์ˆ˜ (array_merge, + ์—ฐ์‚ฐ์ž)์™€ #๋ฐฐ์—ด๋ถ„ํ• ํ•จ์ˆ˜ (array_slice) ๊ทธ๋ฆฌ๊ณ  #๊ธฐํƒ€๋ฐฐ์—ดํ•จ์ˆ˜ (count, in_array, array_keys, array_values, array_unique, array_reverse) ๋“ฑ ์œ ์šฉํ•œ ํ•จ์ˆ˜๋“ค์„ ์ตํ˜”์Šต๋‹ˆ๋‹ค.

์ด ํ•จ์ˆ˜๋“ค์„ ์ˆ™์ง€ํ•˜๋ฉด ์‹ค์ œ PHP ํ”„๋กœ์ ํŠธ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃจ๋Š” ๋ฐ ํฐ ๋„์›€์ด ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์œผ๋กœ PHP ์ดˆ๊ธ‰ 6์ฃผ์ฐจ ๋ฐฐ์—ด์— ๋Œ€ํ•œ ๋ชจ๋“  ๊ฐ•์˜๋ฅผ ๋งˆ์นฉ๋‹ˆ๋‹ค