如何在php中将String(16)转换为Int(1)

For instance

<div ng-repeat = 'list in lists'>

<?php 

 $user_post_id = "{{list.user.id}}";          //this syntax works
 var_dump($user_post_id);                     // gives String(16) '1'     
 $user_post_int_id = (int)$user_post_id;      // change from string to int
 var_dump($user_post_int_id);                 // gives int(1) 0, I don't know why isn't type conversion working!

 echo $user_post_id;                         // echoes out 1
 echo $user_post_int_id;                     //echoes out the 0

So the main problem I think is of type conversion, as I tried one more thing where String(1) is converting to int(1) with no problem but with string(16) everything blows apart and results to 0.

i got 3 suggestion 4u (on my server all works fine)

as a original with my comments:

<div ng-repeat = 'list in lists'>

<?php 

 $user_post_id = "{{list.user.id}}";          //this syntax works
 var_dump($user_post_id);                     // gives String(16) '1'     
 $user_post_int_id = (int)$user_post_id;      // change to int
 var_dump($user_post_int_id);                 
// gives int(1) 1, is not test your php/server conf!

 echo $user_post_id;                         // echoes out 1
 echo $user_post_int_id;                     //echoes out 1

then i advise you to try with your code, run on your server with changes:

  1. replace $user_post_id = "{{list.user.id}}"; to $user_post_id = (int){{list.user.id}}; //hopes your php wudn't show an error

  2. replace $user_post_int_id = (int)$user_post_id; to $user_post_int_id = floor((int)$user_post_id); or $user_post_int_id = ceil((int)$user_post_id);

  3. replace $user_post_id = "{{list.user.id}}"; to $user_post_id = (int)({{list.user.id}}) + 1 ; or plus zero, these hack sometimes works for me !

p.s. (int) can do a trick with you, php can thout that you uses hex bin or smth else. retest it twice ! php.net/manual/en/language.types.integer.php php.net/manual/en/language.types.type-juggling.php

You cannot use Angular expression inside a server side statements, as Angular statement runs on client side after running all server logic.

In your code:

<div ng-repeat = 'list in lists'>

<?php 

 $user_post_id = "{{list.user.id}}"          //list.user.id is a JS variable, you cannot use it in PHP.
 $user_post_int_id = (int)$user_post_id;     // something wrong here, you do not need this step, normally if you retrieved the code from server side.

 {{ $user_post_int_id }}                     //this should not work

But still this blade function fails

@if(Auth::user()->id == $user_post_int_id)
do something //returns false, makes alot of sense, as again you are trying to get variables from JS and passing them to PHP scripts. This will never work.
@endif