PHP : array_push($myArray, 6);PHP++ : $myArray.append(6)PHP : $myArray = array_map($f, array(1, 2, 3, 4);PHP++ : $myArray = array(1, 2, 3, 4).map($f);
PHP : $monArray = array(1, 2, 3, 4, 5);C++ : int monArray[] = {1, 2, 3, 4, 5};Python : monArray = [1, 2, 3, 4, 5]
PHP : $rules = array(1=>array(1, 2, 3), 2=>array(2, 3, 4), 3=>array(3, 4, 5), 4=>array(5, 6, 7), 5=>array(6, 7, 8), 6=>array(7, 8, 9));C++ : int rules[7][3] = {{0, 0, 0}, {1, 2, 3}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, 8}, {}7, 8, 9};Python : rules = [[], [1, 2, 3], [2, 3, 4], [3, 4, 5], [5, 6, 7], [6, 7, 8], [7, 8, 9]]
Vérifier la présence d'un élémentPHP : if (in_array('x', $myArray))Python : if 'x' in myArray:Appender un arrayPHP : $myArray = array_push($myArray, array(1, 2, 3, 4));Python : myArray += [1, 2, 3, 4]Prendre une partie de l'arrayPHP : $array2 = array_slice($myArray, 0, 3)Python : array2 = myArray[0, 3]Dernier exemple, sur les ensembles. Différence de 2 ensembles.PHP : $result = array_diff($set1, $set2);Python : result = set1 - set2
$myArray = array("I", "Love", "NC");print_r(array_rand($myArray, 2));
tab = [] # tableau videprix = [30, 400, 25, 73] # tableau contenant des entiersputs prix # affichage de toutes les valeurs du tableau langues = ["fr", "en"] # tableau de chaînes de caractèresputs langues mix = 4, "quatre" # tableau mixteputs mix
if myList.length() > 10: # Si maListe longueur > 10if len(myList) > 10: # Si longueur maListe > 10