Bird
0
0

You have an array of numbers: [1, 2, 3, 4]. How do you create a string "1-2-3-4" using implode?

hard📝 Application Q8 of 15
PHP - String Functions
You have an array of numbers: [1, 2, 3, 4]. How do you create a string "1-2-3-4" using implode?
Ajoin([1, 2, 3, 4], -);
Bimplode('-', [1, 2, 3, 4]);
Cimplode([1, 2, 3, 4], -);
Dimplode('-', '1,2,3,4');
Step-by-Step Solution
Solution:
  1. Step 1: Use implode with correct argument order

    Separator '-' first, then the array of numbers.
  2. Step 2: Confirm array type and output

    Array of numbers is valid; implode converts numbers to strings and joins them.
  3. Final Answer:

    implode('-', [1, 2, 3, 4]); -> Option B
  4. Quick Check:

    implode('-', array) joins numbers with '-' [OK]
Quick Trick: implode converts numbers to strings automatically [OK]
Common Mistakes:
  • Swapping arguments
  • Passing string instead of array
  • Using join with wrong argument order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes