Jump to content

shamuraq

Members
  • Posts

    142
  • Joined

  • Last visited

About shamuraq

  • Birthday 07/24/1978

Contact Methods

Profile Information

  • Gender
    Male
  • Location
    Singapore;Indonesia

shamuraq's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Hi, I have an array that i want to 'echo' in a foreach loop: foreach($numbers as $num){ echo $num.':'; } i need the output to be 459:534:141 instead of 459:534:141:. How do i remove the ':' at the final loop? Thanx in advance.
  2. I have this list as an array: 1. [Question - Geography Chapter2] How would you describe humans' relationship with the physical environment? (Page 42) 2. [Question - Geography Chapter4] What is a natural resource? (Page 67) 3. [Question - Geography Chapter3] What are two or three resources which you cannot do without? What are the reasons for your choices? (Page 52) ... 129. [Question - Geography Chapter6] What is the human-centered view on the use of natural resources? (Page 339) 130. [Question - Geography Chapter7] What are the benefits of using products with a smaller environmental footprint? (Page 342) I would like to remove: - The square brackets and everything in it. I am hoping that the questions would start without the eg; [Question - Geography Chapter7] etc. - The round brackets and everything in it. I am trying to delete the references to the page number. Is there a simple an clean way to do it? Any pointer is truly appreciated. Thanx in advance.
  3. What does the values in 0,5 in substr($v, 0, 5) refers to?
  4. I tried as suggested: $arrFiles = array(); $dirPath = "./"; $files = scandir($dirPath); $required = array_filter($files, fn($v)=>str_starts_with($v, 'alg00')); echo '<pre>' . print_r($required, 1) . '</pre>'; The error: Fatal error: Uncaught Error: Call to undefined function str_starts_with() ...php:29 Stack trace: #0 [internal function]: {closure}('.') #1 /...php(29): array_filter(Array, Object(Closure)) #2 {main} thrown in ...php on line 29
  5. Hi guysm I have a folder containing these files: alg001.php alg002.php alg003.php alg004.php alg005.php algComp.php ranFrac.php ranalg.php randec.php randint.php I would only like to store the names of files alg001.php, alg002.php, alg003.php, alg004.php, alg005.php into an array. How do i achieve this with preg match?
  6. how do i convert the following script to adopt ternary operator to shorten it? $radint = mt_rand(1,33); $flip = mt_rand(1,2); if($flip == 2){ $radint *= -1; } Thanx in advance.
  7. Tes... Thats exactly what i wanted. But can you explain the breakdown of "%-35 = %5d <br>"?
  8. I have a function randomly take 4 unique numbers from an array and multiply them. Problem with the script below is it only print out the products. I would like for each set of 4 numbers and its product to be in its own array and all the arrays into a main array, forming a 2 dimensional array. My current script: //Pruning outcome from controlled lists of Prime Numbers $primes = array(2, 3, 5, 7, 11, 13, 17, 19, 23); function getAllCombinations($arr, $n, $selected = array(), $startIndex = 0) { if ($n == 0) { $product = 1; foreach ($selected as $prime) { $pr[] = $prime; $product *= $prime; $pr[] = $prime; } echo "Product: $product\n"; return; } for ($i = $startIndex; $i < count($arr); $i++) { $selected[] = $arr[$i]; getAllCombinations($arr, $n - 1, $selected, $i + 1); array_pop($selected); // Backtrack and remove the element for next iteration } } getAllCombinations($primes, 4); The output: Product: 210 Product: 330 Product: 390 Product: 510, etc. The preferred method is a 2 dimensional array as such: [0][0] =>2 [0][1] =>3 [0][2]=>5 [0][3]=>7 and the product would be in [0][4] =>210 [1][0] =>2 [1][1] =>3 [1][2]=>5 [1][3]=>11 and the product would be in [1][4] =>330 etc. Any pointers is greatly appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.