+20

# [Explanation] PHP Questions...

1.This Question is from PHP Challenge. 2.See the questions👇,I know it's easy but I am not able to understand,i lose many times in this question,if you understand this codes then explain me in detail. 3.\$matrix = array( array(1,7,4) array(5,9,8) array(3,0,2) ); \$n = count(\$matrix) - 1; for( \$i = 0; \$i <= \$n; \$i++){ \$temp = \$matrix [ \$i ][ \$i ]; \$matrix [ \$i ][ \$i ] = \$matrix [\$i] [ \$n - \$i ]; matrix [ \$i ][ \$n - \$i ] = \$temp; } echo \$matrix[ 2 ] [ 0 ] . \$matrix[ 0 ][ 2 ]; 4.\$secret=(3%5==3)?1:0; \$answer=(!(6+5>5+5 xor 1))?2+ \$secret:1; echo \$answer; 5.i want to know who is best,who gives better answer

9/29/2020 7:53:28 AM

++༒192.168.00.000༒++

+10

(1) Basically the code swaps 2 elements in each array. The swapping affects on matrix[\$i][\$n - \$i], which is matrix[0][0] <-> matrix[0][2] matrix[1][1] <-> matrix[1][1] No effect matrix[2][2] <-> matrix[2][0] The matrix becomes {4,7,1} {5,9,8} {2,0,3} \$matrix[2][0] -> 2 \$matrix[0][2] -> 1 (2) brief doc about ternary operator: cond ? ifTrue : elseFalse if the condition is true, evaluates ifTrue expression, else evaluates elseFalse expression. So \$secret is 1. !(6 + 5 > 5 + 5 xor 1) > has higher precedence than xor. !(1 xor 1) xor is != in bits world. It compares each bits of 2 operands and returns a number depends on the bits. xor returns 1 if the 2 bits are different, else returns 0. 1 xor 1 = 0 !0 = 1, which is true. so 2 + \$secret is evaluated. \$answer = 2 + 1 = 3.

+7

+7

+6

+6

CarrieForle Thank you so much😄

+5

Vadivelan Finally \$matrix[0][2]=1,\$matrix[2][0]=2 So output will be 21 You have written incorrectly,thanks for your answer , I understood and my 2 Question is correct

+5

Vadivelan as I mentioned above, cond : ifTrue : elseFalse If cond is false, 1 will be evaluated and \$answer will be 1. But in this case !(1 xor 1), this condition is true. So 1 won't be evaluated and instead 2 + \$answer is evaluated.

+4

https://code.sololearn.com/w1iPBPgC0i08/?ref=app I hope you understand! I think your 2nd code is incorrect. Please check this, then I do explain.

+4

CarrieForle Thanks. If there written as (2+\$secret):1, it will easily understand. But, there no brackets, so I confused.

+3

༄ᶦᶰᵈ᭄𝕌𝕛𝕛𝕒𝕨𝕒𝕝 💫 I've updated my answer.

0

The great php learning cod