<html> <p><img src="https://steemitimages.com/0x0/https://bbvaopen4u.com/sites/default/files/img/new/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg" width="2122" height="1415"/></p> <p> <a href="https://bbvaopen4u.com/sites/default/files/img/new/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg">Image Source</a> </p> <h2>Repository</h2> <p> <a href="https://github.com/php/php-src">https://github.com/php/php-src</a> </p> <h2>What Will I Learn?</h2> <p>I will learn the array methods part 1 we have the sort, rsort fo the indexed arrays and ksort, krsort for the associative arrays , and array reverse, shuffle methods .</p> <ul> <li>Sort and Rsort methods for the indexed arrays</li> <li>Ksort and Krsort for the associative arrays</li> <li>Array Reverse and Shuffle methods</li> </ul> <h2>Requirements</h2> <ul> <li>Server support PHP , Xampp or Wamp for example</li> <li>An IDE like Sublime text.</li> <li>Browser (Chrome for example)</li> </ul> <h2>Difficulty</h2> <ul> <li>Basic</li> </ul> <h2>Description </h2> <p> In this tutorial we will continue our series about the PHP programming language, we will talk about the arrays methods "Sort , Rsort " for the indexed arrays , " Ksort , Krsort " for the associative arrays , Reverse and Shuffle methods , let's start ..</p> <h3>1- Sort Method :</h3> <p> This method is used to rank array from the smallest to the largest , it's sensitive to the case of characters, the letter ' A' is smaller than the letter ' Z ' and the letter ' Z ' smaller than ' a ' , if the comparison of two elements is equal their relative order in the ordred array is not specified.</p> <p>You can pass two parameters for this array , the first is the array that you want to sort and the second is the sorting type and there is many types : </p> <ul> <li>SORT_REGULAR : To compare items naturally</li> <li>SORT_STRING : To compare string items</li> </ul> <p>To use the sort method we need to pass the array as parameter :</p> <p><code>sort($array, type);</code></p> <p>The type is by default " SORT_REGULAR" it's optional, it will sort the array in ascending order this is the result of this method .</p> <p><img src="https://e.top4top.net/p_980xgaos1.png" width="579" height="329"/></p> <h3>2- Rsort Method :</h3> <p>The reverse sort method arranges the array in reverse order, maintains the same proprieties as the sort method, from the largest to the smallest, if the comparison of two elements is equal their relative order in the ordred array is not specified.</p> <p>It has the same sorting types like the previous method, it specifies new keys for elements in the array , it will remove any existing keys you have already specified instead of simply rearranging the keys.</p> <p>To use the rsort method we need to pass the array as parameter :</p> <p><code>rsort($array, type);</code></p> <p>I will sort the results in the reverse order</p> <p><img src="https://e.top4top.net/p_980irdrl1.png" width="869" height="320"/></p> <h3>3- Ksort Method :</h3> <p>This method used to rank an associative array in the ascending order, it means from the smallest to the largest, it arranges an array by key, and maintains the association of the indexes with their associated values, which is primarily useful in associative arrays.</p> <p>It returns ' TRUE ' when it succeeds at work and ' FALSE ' when it fails.</p> <p>To use the ksort method we need to pass the array as parameter :</p> <p><code>ksort($array, type);</code></p> <p>I will sort the materials array by key using the ksort method and this is the result </p> <p><img src="https://e.top4top.net/p_980ndd1g1.png" width="540" height="303"/></p> <h3>4- Krsort Method :</h3> <p>This method used to rank an associative method in the descending order, it means from the largest to the smallest, it has two parameters the array and the sorting type, we have many other types :</p> <ul> <li>SORT_LOCAL_STRING</li> <li>SORT_NATURAL</li> <li>SORT_FLAG_CASE</li> </ul> <p>To use the krsort method we need to pass the array as parameter :</p> <p><code>krsort($array, type);</code></p> <p>To print the array am using the foreach loop and this the result after the reverse sort</p> <p><img src="https://b.top4top.net/p_980upxvt1.png" width="802" height="296"/></p> <h3>5- Array Reverse Method :</h3> <p>The array reverse used to reverse the order of the array, it doesn't do any type of the sorting types, it just reverse the order of keys and values from the top to bottom without any defect in the content.</p> <p>To use the reverse array we need to define new array and this is the syntax :</p> <p><code>$reversedArray = array_reverse($array);</code></p> <p>I will reverse the indexed array and the associative array to see the difference between the sort and the reverse </p> <p><img src="https://c.top4top.net/p_980czw371.png" width="1208" height="631"/></p> <h3>6- Shuffle Method :</h3> <p>The shuffle method mixes the elements of the array by arranging them randomly, a random number genrator is used, when each refresh of the page the array will be arranged differently.</p> <p>To use the shuffle method we just pass the array as parameter </p> <p><code>shuffle($array);</code></p> <p>The shuffle method helps us a lot, to see the benifit of it we will use an example of question game, when you reload the page you will get a different question</p> <p><code>$questions = array(</code></p> <p><code>"What's your name ?",</code></p> <p><code>"What's your job ?",</code></p> <p><code>"How old are you ?",</code></p> <p><code>"Where are you from ?"</code></p> <p><code>);</code></p> <p>This is my array we have 4 questions and to display the question I will use this code</p> <p><code><?php</code></p> <p><code>shuffle($questions);</code></p> <p><code>echo "<h4>" . $questions[1] . "</h4>";</code></p> <p><code>?></code></p> <p>I will always print the second item in h4 element , after that I have an input with button to answer the question</p> <p><img src="https://c.top4top.net/p_980pgmfm1.png" width="312" height="147"/></p> <p>This is the question in the second position , and when I reload my page this is the result </p> <p><img src="https://d.top4top.net/p_980wol6x2.png" width="299" height="155"/></p> <h2>Video Tutorial</h2> <p>https://www.youtube.com/watch?v=TiSwlkzNJto&t=11s</p> <h2>Curriculum</h2> <ul> <li> <a href="https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-01-indexed-arrays-associative-arrays-and-multidimensional-arrays">PHP Tutorial #01 Indexed Arrays, Associative Arrays and Multidimensional Arrays</a></li> </ul> <h2>Proof of Work Done</h2> <p>https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/methods1.php</p> </html>
author | alexendre-maxim |
---|---|
permlink | php-tutorial-02-array-methods-sort-rsort-ksort-krsort-arrayreverse-and-shuffle |
category | utopian-io |
json_metadata | {"tags":["utopian-io","video-tutorials","video","programming"],"image":["https://steemitimages.com/0x0/https://bbvaopen4u.com/sites/default/files/img/new/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg","https://e.top4top.net/p_980xgaos1.png","https://e.top4top.net/p_980irdrl1.png","https://e.top4top.net/p_980ndd1g1.png","https://b.top4top.net/p_980upxvt1.png","https://c.top4top.net/p_980czw371.png","https://c.top4top.net/p_980pgmfm1.png","https://d.top4top.net/p_980wol6x2.png","https://img.youtube.com/vi/TiSwlkzNJto/0.jpg"],"links":["https://bbvaopen4u.com/sites/default/files/img/new/bbva-open4u-herramientas-basicas-desarrolladores-php_1.jpg","https://github.com/php/php-src","https://www.youtube.com/watch?v=TiSwlkzNJto&t=11s","https://steemit.com/utopian-io/@alexendre-maxim/php-tutorial-01-indexed-arrays-associative-arrays-and-multidimensional-arrays","https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/methods1.php"],"app":"steemit/0.1","format":"html"} |
created | 2018-09-07 23:57:21 |
last_update | 2018-09-11 21:41:06 |
depth | 0 |
children | 8 |
last_payout | 2018-09-14 23:57:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 17.580 HBD |
curator_payout_value | 5.597 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 6,788 |
author_reputation | 18,071,828,077,109 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,652,269 |
net_rshares | 22,359,574,458,836 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
yuxi | 0 | 3,051,023,240 | 10% | ||
luigi-tecnologo | 0 | 1,239,174,202 | 4% | ||
rafalski | 0 | 38,259,792,390 | 78% | ||
bachuslib | 0 | 19,997,633,444 | 100% | ||
aafeng | 0 | 4,704,053,457 | 8% | ||
buckydurddle | 0 | 38,900,386,343 | 100% | ||
utopian-io | 0 | 22,004,811,374,129 | 14.8% | ||
jaff8 | 0 | 66,126,318,224 | 100% | ||
amosbastian | 0 | 10,559,879,575 | 18.45% | ||
organicgardener | 0 | 931,763,715 | 10% | ||
mirkosche | 0 | 483,846,551 | 100% | ||
alexendre-maxim | 0 | 6,833,487,309 | 100% | ||
simplymike | 0 | 18,457,204,171 | 15% | ||
ayay | 0 | 95,505,615 | 11% | ||
javicuesta | 0 | 1,316,766,281 | 50% | ||
clayjohn | 0 | 18,921,087,830 | 100% | ||
fidal07 | 0 | 501,674,289 | 100% | ||
bogeva | 0 | 493,312,829 | 100% | ||
lolitasmits | 0 | 516,353,864 | 100% | ||
sergeidurov | 0 | 507,700,395 | 100% | ||
varikoz | 0 | 488,979,838 | 100% | ||
dbrowskim | 0 | 492,700,096 | 100% | ||
maluninivan | 0 | 494,250,142 | 100% | ||
meyukekogev | 0 | 496,580,970 | 100% | ||
sonagalstyan | 0 | 496,396,479 | 100% | ||
ionov57 | 0 | 486,922,745 | 100% | ||
theeide | 0 | 487,045,963 | 100% | ||
ylikov.denis | 0 | 496,292,153 | 100% | ||
sidorovaval | 0 | 514,632,226 | 100% | ||
brantleyja | 0 | 492,778,177 | 100% | ||
rubydetails | 0 | 496,216,158 | 100% | ||
mightypanda | 0 | 20,256,587,809 | 50% | ||
hearttoasting | 0 | 502,412,100 | 100% | ||
retrievesalsa | 0 | 496,780,909 | 100% | ||
graphbaggy | 0 | 481,262,327 | 100% | ||
hoovesreport | 0 | 490,951,263 | 100% | ||
gunpowderwigeon | 0 | 489,791,484 | 100% | ||
targetfile | 0 | 496,767,813 | 100% | ||
tamilaisaeva | 0 | 480,599,193 | 100% | ||
kernovanatali | 0 | 485,529,562 | 100% | ||
andreiakilov | 0 | 530,347,303 | 100% | ||
stacykingsman | 0 | 502,904,165 | 100% | ||
nikolay.suhoruk | 0 | 487,568,392 | 100% | ||
ricklargo | 0 | 493,924,510 | 100% | ||
olgafalatova | 0 | 487,922,021 | 100% | ||
drinkschin | 0 | 511,565,938 | 100% | ||
curiouscred | 0 | 502,805,723 | 100% | ||
desktopcarrots | 0 | 521,301,359 | 100% | ||
fastandcurious | 0 | 3,958,310,519 | 100% | ||
coinsicy | 0 | 506,341,810 | 100% | ||
doorpedal | 0 | 487,969,413 | 100% | ||
ibogosov | 0 | 496,714,173 | 100% | ||
iauns | 0 | 75,457,139,113 | 100% | ||
jacekw.dev | 0 | 1,998,826,675 | 100% | ||
benmopping | 0 | 476,456,719 | 100% | ||
bullinachinashop | 0 | 3,303,349,585 | 100% | ||
aljager78 | 0 | 494,571,707 | 100% | ||
neshferdin | 0 | 506,682,630 | 100% | ||
sabitovv | 0 | 503,463,333 | 100% | ||
ilovecoding | 0 | 920,418,712 | 10% | ||
danniguise | 0 | 94,059,776 | 100% |
Good work @alexendre-maxim. You were well organized and I feel that your presentation has improved greatly. Good work. I suggest that you turn off notifications on your computer when you are recording. A couple of times a chime gave me a fright :) Also, for the "Proof of Work" you presented the video again. I think this may have been an error. Good work Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category. To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/9/222422323). ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | buckydurddle |
---|---|
permlink | re-alexendre-maxim-php-tutorial-02-array-methods-sort-rsort-ksort-krsort-arrayreverse-and-shuffle-20180911t203725368z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"users":["alexendre-maxim"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/9/222422323","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-09-11 20:37:24 |
last_update | 2018-09-11 20:37:24 |
depth | 1 |
children | 3 |
last_payout | 2018-09-18 20:37:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 6.271 HBD |
curator_payout_value | 2.036 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 855 |
author_reputation | 101,965,608,464,038 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 71,019,195 |
net_rshares | 8,106,518,986,324 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 16,604,295,979 | 15% | ||
utopian-io | 0 | 8,060,910,341,661 | 5.35% | ||
amosbastian | 0 | 5,284,360,653 | 8.73% | ||
organicgardener | 0 | 1,921,840,544 | 25% | ||
alexendre-maxim | 0 | 7,212,915,566 | 100% | ||
reazuliqbal | 0 | 8,167,323,775 | 12% | ||
mightypanda | 0 | 6,078,179,970 | 15% | ||
mops2e | 0 | 339,728,176 | 10% |
Thank you @buckydurddle , I am happy to your encourage always , I have copied the wrong link for the proof of work and I have edited it , I will block all the notifications , thank you again sir.
author | alexendre-maxim |
---|---|
permlink | re-buckydurddle-re-alexendre-maxim-php-tutorial-02-array-methods-sort-rsort-ksort-krsort-arrayreverse-and-shuffle-20180911t214404991z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"users":["buckydurddle"],"app":"steemit/0.1"} |
created | 2018-09-11 21:44:24 |
last_update | 2018-09-11 21:44:24 |
depth | 2 |
children | 1 |
last_payout | 2018-09-18 21:44:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 195 |
author_reputation | 18,071,828,077,109 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 71,023,527 |
net_rshares | 4,668,046,361 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
buckydurddle | 0 | 4,668,046,361 | 12% |
Thanks. Keep up the good work :)
author | buckydurddle |
---|---|
permlink | re-alexendre-maxim-re-buckydurddle-re-alexendre-maxim-php-tutorial-02-array-methods-sort-rsort-ksort-krsort-arrayreverse-and-shuffle-20180911t214903673z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-09-11 21:49:03 |
last_update | 2018-09-11 21:49:03 |
depth | 3 |
children | 0 |
last_payout | 2018-09-18 21:49:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 32 |
author_reputation | 101,965,608,464,038 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 71,023,775 |
net_rshares | 0 |
Thank you for your review, @buckydurddle! So far this week you've reviewed 4 contributions. Keep up the good work!
author | utopian-io |
---|---|
permlink | re-re-alexendre-maxim-php-tutorial-02-array-methods-sort-rsort-ksort-krsort-arrayreverse-and-shuffle-20180911t203725368z-20180916t025212z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-09-16 02:52:12 |
last_update | 2018-09-16 02:52:12 |
depth | 2 |
children | 0 |
last_payout | 2018-09-23 02:52:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 115 |
author_reputation | 152,955,367,999,756 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 71,411,123 |
net_rshares | 0 |
Hello! Your post has been resteemed and upvoted by @ilovecoding because **we love coding**! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On!  *Reply !stop to disable the comment. Thanks!*
author | ilovecoding |
---|---|
permlink | 20180907t235736394z |
category | utopian-io |
json_metadata | {"tags":["ilovecoding"],"app":"ilovecoding"} |
created | 2018-09-07 23:57:36 |
last_update | 2018-09-07 23:57:36 |
depth | 1 |
children | 1 |
last_payout | 2018-09-14 23:57:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 323 |
author_reputation | 40,845,997,808 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,652,282 |
net_rshares | 7,221,874,979 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
alexendre-maxim | 0 | 6,730,984,999 | 100% | ||
ilovecoding | 0 | 490,889,980 | 5% |
Thank you
author | alexendre-maxim |
---|---|
permlink | re-ilovecoding-20180907t235736394z-20180907t235904444z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-09-07 23:59:21 |
last_update | 2018-09-07 23:59:21 |
depth | 2 |
children | 0 |
last_payout | 2018-09-14 23:59:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 9 |
author_reputation | 18,071,828,077,109 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 70,652,366 |
net_rshares | 0 |
Hey, @alexendre-maxim! **Thanks for contributing on Utopian**. Weβre already looking forward to your next contribution! **Get higher incentives and support Utopian.io!** Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)). **Want to chat? Join us on Discord https://discord.gg/h52nFrV.** <a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
author | utopian-io |
---|---|
permlink | re-php-tutorial-02-array-methods-sort-rsort-ksort-krsort-arrayreverse-and-shuffle-20180911t211043z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-09-11 21:10:45 |
last_update | 2018-09-11 21:10:45 |
depth | 1 |
children | 1 |
last_payout | 2018-09-18 21:10:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 597 |
author_reputation | 152,955,367,999,756 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 71,021,425 |
net_rshares | 0 |
Thank you
author | alexendre-maxim |
---|---|
permlink | re-utopian-io-re-php-tutorial-02-array-methods-sort-rsort-ksort-krsort-arrayreverse-and-shuffle-20180911t211043z-20180911t214437658z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-09-11 21:44:57 |
last_update | 2018-09-11 21:44:57 |
depth | 2 |
children | 0 |
last_payout | 2018-09-18 21:44:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 9 |
author_reputation | 18,071,828,077,109 |
root_title | "PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 71,023,552 |
net_rshares | 0 |