PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 12, 2022

[FIXED] I want to display the following numbers in Loop 1 to 6

 February 12, 2022     for-loop, laravel, laravel-8     No comments   

Issue

I want to display the following numbers in Loop 1 to 6 like this: 1 - 2

2 - 3

3 - 4

5 - 6


Solution

$range = range(1, 6);
foreach ($range as $key => $value) {
  if ($key != 0) {
    echo $range[$key - 1].' - '.$range[$key].PHP_EOL;
  }
}

@php($range = range(1, 6))
@foreach ($range as $key => $value)
  @if (!$loop->first())
    <p>{{ $range[$key - 1] }} - {{ $range[$key] }}</p>
  @endif
@endforeach


Answered By - IGP
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,217,785

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing