PHP 7 : How to generate zend_string variable of length 0 - php-7

I am working in PHP 7, I have a case in which i want to pass a string of length 0. so how can we generate zend_string variable of length 0.
I tried assigning NULL to zend_string variable but down the line code crashed because it is trying to dereference NULL. so I am guessing we need to allocate memory to zend_string variable and whole value NULL or string length is 0.

A quick scan of the source shows a few examples of this:
zend_string *str;
str = zend_string_alloc(sizeof("") - 1, 0);

Related

How do I build a variable from a character repeated N number of times, in Lua?

I have an input value of N.
I want to turn that into a variable consisting of N characters.
for example, if N = 12, and I'm repeating the character "H", the value of the created variable should look like this: "HHHHHHHHHHHH"
I need it to be a variable, because I intend to use it in a few other places.
I am completely new to Lua, by the way. I just started a few days ago.
You are looking for string.rep.
For example:
local result = string.rep("H", 12)
print(result) -- prints "HHHHHHHHHHHH"
The datatype string has a metatable with all string functions attached as methods in __index.
Therefore you also can do...
local str, N = "H", 12
str = str:rep(N)
You can use the load() function to do it.
load(string.format("%s=4711", string.rep("H", 12)))()
print(HHHHHHHHHHHH)

Removed the last element from a json[]?

I have a json[] array (_result_group) in PostgreSQL 9.4, and I want to remove its last json element (_current). I prepared with:
_result_group := (SELECT array_append(_result_group,_current));
And tried to remove with:
SELECT _result_group[1:array_length(_result_group,1) -1] INTO _result_group;
But it didn't work.
How to do this?
To remove the last element from any array (including json[]) with the means of Postgres 9.4, obviously within plpgsql code:
_result_group := _result_group[1:cardinality(_result_group)-1];
Assuming a 1-dimensional array with default subscripts starting with 1.
You get an empty array for empty array input and null for null.
According to the manual, cardinality() ...
returns the total number of elements in the array, or 0 if the array is empty
Then just take the array slice from 1 to cardinality -1.
Then again, your attempt should work as well:
SELECT _result_group[1:array_length(_result_group,1) -1] INTO _result_group;
For non-standard array subscripts see:
Normalize array subscripts for 1-dimensional array so they start with 1

Bitwise "and" operation into the kotlin

If negative number is from -31 to -1 then I would like represent it into the format 111XXXXX.
I try to do it using "and" bitwise operator:
println("0b00011111 & 0xe0 is ${0b00011111 and 0xe0}")
println("31 & 0xe0 is ${31 and 0xe0}")
println("0b00011111 & 0b11100000 is ${0b00011111 and 0b11100000}")
But the result is always 0. Where did I make the mistake?
It prints 0 because 00011111 and 11100000 always returns 0. The return type of and is Int, so if you want to print it in base 2 with leading zeroes, you have to format it.
To convert it to a String in base 2, you can call the toString method on Int with a radix parameter:
val numberString = (0b00011111 and 0b11100000).toString(2);
This will give you the number in binary format, but without leading zeroes. You need to left-pad with zeroes to get the format you want. I leave that task up to you (hint: padStart) ;)

Octave keyboard input function to filter concatenated string and integer?

if we write 12wkd3, how to choose/filter 123 as integer in octave?
example in octave:
A = input("A?\n")
A?
12wkd3
A = 123
while 12wkd3 is user keyboard input and A = 123 is the expected answer.
assuming that the general form you're looking for is taking an arbitrary string from the user input, removing anything non-numeric, and storing the result it as an integer:
A = input("A? /n",'s');
A = int32(str2num(A(isdigit(A))));
example output:
A?
324bhtk.p89u34
A = 3248934
to clarify what's written above:
in the input statement, the 's' argument causes the answer to get stored as a string, otherwise it's evaluated by Octave first. most inputs would produce errors, others may be interpreted as functions or variables.
isdigit(A) produces a logical array of values for A with a 1 for any character that is a 0-9 number, and 0 otherwise.
isdigit('a1 3 b.') = [0 1 0 1 0 0 0]
A(isdigit(A)) will produce a substring from A using only those values corresponding to a 1 in the logical array above.
A(isdigit(A)) = 13
that still returns a string, so you need to convert it into a number using str2num(). that, however, outputs a double precision number. so finally to get it to be an integer you can use int32()

Explain why storing the value of printf in a variable and then printing it gives an extra value?

int d;
d=printf("\n%d%d%d%d",1,2,3,4);
printf("%d",d);
The code gives the output as 1,2,3,4,5.
I don't understand why an integer greater than the last one is being printed.
printf returns the total number of characters written. In the first printf call that is 4 digits from the 4 variables and the newline character which adds up to 5. So the return value is 5 which is what you get in the second call.