I am currently trying to resolve a problem with changing the type of a variable in order to be able to do math operations with it. I am trying to enhance a Wordpress plugin called "WooCommerce PDF Invoices & Packing Slips".
There is a variable $item['order_price'], which contains a price with a currency sign. var_dump() of this variable returns string(48)"709 Kč".
When I try to get the integer value using either intval() or casting it via (int), it returns 0.
What could be the solution?
Just try
filter_var($item['order_price'], FILTER_SANITIZE_NUMBER_INT);
I suggest you use at least : trim($item['order_price']);
Related
Please help me. how to display only value on Laravel.
when i'm var_dump($data->count_date)
i got like this.
int(347)
how to remove int()?
Thks
php var_dump — Dumps information about a variable, not the variable alone.
$data->count_date is an integer number value, you can use it like any other integer, for example:
$value=$data->count_date+1;
Just do, It will only return the value.
dd($data->count_date);
i need change all fields integer to string, how can do? i am using php, laravel, mysql.
The reason is because i need to set the value from the database in
input select, to that I am using angularjs, I know that there are a lots of ways to resolve that. But I have a form with 2.5k lines and almost 40 input select so I need a fix easy.
PHP will interpret the variable as the type you use it as. If you append a number to a string, it becomes a string.
$var = 12;
var_dump($var); // I am an integer
var_dump("{$var}"); // I am a string
I am trying to use the following functionality:
[quote_elements.product.factor;ope=mul:quote_elements.qty]
But all I get is always 0.
if I use:
[quote_elements.product.factor;ope=mul:4]
it works fine and I get 4 times the factor number.
But this is not what I need. I need to multiply dynamically the factor with the quantity. this can be for each row different.
any tips what I am missing here?
Embedded TBS fields does not work in parameter ope.
That why the string « quote_elements.qty » is always converted to 0.
Parameter ope=mul can work only with fixed values.
In order to solve you problem, you can use a custom ondata function. It will enable you to add a calculated column in you record before to merge it.
PHP side:
function f_my_ondata($BlockName, &$CurrRec, $RecNum) {
$CurrRec['my_result'] = $CurrRec['product']['factore'] * $CurrRec['qty'];
}
Template side :
[quote_elements;block=...;ondata=f_my_ondata] // block definition
...
[quote_elements.my_result]
I am trying to restrict content within a Wordpress template file and am using a plugin called Paid Memberships Pro to do so.
The code below restricts content to members with 'levels' of 1 or 2.
if(pmPro_hasMembershipLevel(array(1,2))){
restricted content goes here
}
The problem comes when I try to use a variable to provide the levels. These levels are held in a custom field group 'restrictions' with field name 'pmpro_id'. I access these levels within the template using...
foreach($restrictions as $restriction){
$temp=get_field('pmpro_id', $restriction->ID );
$temp_array[]=$temp;
}
$levels=implode(',', $temp_array);
If I then pass $levels to pmPro_hasMembershipLevel, this works fine if there is only one level but fails if there are 2 or more. I believe this is because the variable type is then a string rather than integer? I had previously tried to pass the $temp_array directly though I felt this wouldn't work and was correct.
I realise this is probably PHP 101. I have searched but don't really know what I'm looking for to be honest! I am not a developer and this is the last thing holding me back from finishing this project so ANY help anyone could provide would be brilliant. Thanks in advance.
You don't need to implode $temp_array if pmPro_hasMembershipLevel accepts array as its argument. When you implode an array you get string as a return value — that's not what you want here. If you think that the issue might be with the type of values, then you can try to cast them to integers, like this $temp_array[]= (int) $temp;
i'm working with Highcharts, and i'm having some problem with number_format.
formating the number $variable = 1008000 :
number_format($variable, 2,',','.')
the result is: 1.008.000,00 (this is what i need)
but, highcharts transform 1.008.000,00 to 1.008
how can i deal with this problem?
Note that in English the number should be 1,008,000.00
You could either change it in your number_format() call or try changing the decimal point value in Hightcharts (http://www.highcharts.com/ref/#lang)
note one thing, we do not need to set the number format for high chart...
you can pass directly 1008000 it will be auto adjust with this value...
Check this...Good luck
Thanks
Apart from lang parameters http://api.highcharts.com/highstock#lang.thousandsSep you can also use Highcharts.numberFormat() for labels / tooltip which can be used in formatter .
http://api.highcharts.com/highstock#highcharts.numberFormat()
http://api.highcharts.com/highstock#tooltip.formatter