0

How to convert array members to int. My controller code

    public function show()
{
    $i = DB::table('users')->lists('id');
     // var_dump($i);
    return View::make('seat.seatselect')->with('i', $i);
}

When I var_dump($i) it result is as following

array(12) { [0]=> int(5) [1]=> int(14) [2]=> int(16) [3]=> int(17) [4]=> int(18) [5]=> int(19) [6]=> int(20) [7]=> int(21) [8]=> int(22) [9]=> int(23) [10]=> int(24) [11]=> int(26) }

So in my view I call $i. Resu is coming only last value of $i

@foreach($i as $i)
    var bookedSeats = [{{$i}}];
@endforeach

But I want to retrieve the result as followed Example:

var bookedSeats = [1, 2, 3, 4, 5, 6, 7, 9, 13, 56];

How to solve it. Help me please.

2
  • possible duplicate of stackoverflow.com/questions/19333160/… Commented May 7, 2014 at 4:44
  • I know how to call individual objects. But I want put to inside bookedSeats var seperate by comma. Commented May 7, 2014 at 4:55

2 Answers 2

0

If I understood the question correctly, you don't want a PHP variable named $bookedSeats that is set to an array, but a JavaScript array generated from those PHP values. In that case, you could simply do this:

var bookedSeats = [{{ implode(', ', $i) }}];

No need for a foreach. :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks bro. This is working. var bookedSeats = [{{ implode(', ', $i) }}];
0

If this is a js code:

@foreach($i ass $i)
    var bookedSeats = [{{$i}}];
@endforeach

try changing it to:

var bookedSeats = [];
@foreach($i ass $i)
    bookedSeats.push({{ $i }});
@endforeach

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.