Jump to content

danielki

New Members
  • Posts

    2
  • Joined

  • Last visited

danielki's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I am new to php and I am trying to do the following task. I tried to look on the internet for a php function which can help me solve the task but I couldn't come up with any valuable one. Can any one suggest any function or give me a hint on how to solve the following? thank you in advance. Your task is to complete the below program so that it prints as shown in the example. There's only one missing function that you need to write. Just write that missing function in the text box. Incomplete program: <?php // Your code here $charstring = "first\n"; newvalue($charstring); echo "String in the end: $charstring\n"; ?> Example output String in the start: first String in the end: New string
  2. Hello, I am new to php and am trying to do the following task. Complete the following PHP script so that it prints the numbers, given in a form, in a specific order. The script should organize the numbers from largest to the smallest and from smallest to largest and print both of these number strings on screen. The points are sent to the script as a character string, where points are separated with comma (e.g. 4,5,2). Points are divided into an array with the explode-function. Using the sort-function is not allowed. Do the organizing with a for-statement. Incomplete program: <?php $numberstring = $_GET['numberstring']; $array = explode(',',$numberstring); echo "Order in the beginning: $numberstring\n"; // Your code here and only here echo "Largest to smallest: $largest_smallest\n"; echo "Smallest to largest: $smallest_largest\n"; ?> First I tried it if it works with the following straight forward code: $largest_smallest=rsort($numberstring ); $smallest_largest=sort($numberstring ); And it gave me the following error: Order in the beginning: 4,7,-2,0,6 Warning: rsort() expects parameter 1 to be array, string given in /tmp/K2U5XgShJ9/1/.php on line 9 Warning: sort() expects parameter 1 to be array, string given in /tmp/K2U5XgShJ9/1/.php on line 10 Largest to smallest: Smallest to largest: So can any one help me why there is an error and also according to the assignment I am supposed to do it with for statement. what is the equivalent way of sort() or rsort() doing this? thank you so much! Example output: Order in the beginning: 4,7,-2,0,6 Largest to smallest: 7,6,4,0,-2 Smallest to largest: -2,0,4,6,7
×
×
  • 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.