MOD
PHP code
<?php
/*
* Makes the value of "result" congruent to "value1" modulo "value2".
* opcode number: 5
*/
echo 6 % 3;
?>
PHP opcodes
Function name: (null)
Compiled variables: none
line | # | op | fetch | ext | return | operands |
---|---|---|---|---|---|---|
6 | 0 | MOD | ~0 | 6,3 | ||
1 | ECHO | ~0 | ||||
7 | 2 | RETURN | 1 |
- PHP Руководство
- Функции по категориям
- Индекс функций
- Ядро PHP: Руководство хакера
- Zend Engine 2 Opcodes
- ADD
- ADD_ARRAY_ELEMENT
- ADD_CHAR
- ADD_INTERFACE
- ADD_STRING
- ADD_VAR
- ASSIGN
- ASSIGN_ADD
- ASSIGN_BW_AND
- ASSIGN_BW_OR
- ASSIGN_BW_XOR
- ASSIGN_CONCAT
- ASSIGN_DIM
- ASSIGN_DIV
- ASSIGN_MOD
- ASSIGN_MUL
- ASSIGN_OBJ
- ASSIGN_REF
- ASSIGN_SL
- ASSIGN_SR
- ASSIGN_SUB
- BEGIN_SILENCE
- BOOL
- BOOL_NOT
- BOOL_XOR
- BRK
- BW_AND
- BW_NOT
- BW_OR
- BW_XOR
- CASE
- CAST
- CATCH
- CLONE
- CONCAT
- CONT
- DECLARE_CLASS
- DECLARE_CONST
- DECLARE_FUNCTION
- DECLARE_INHERITED_CLASS
- DECLARE_INHERITED_CLASS_DELAYED
- DIV
- DO_FCALL
- DO_FCALL_BY_NAME
- ECHO
- END_SILENCE
- EXIT
- EXT_FCALL_BEGIN
- EXT_FCALL_END
- EXT_NOP
- EXT_STMT
- FE_FETCH
- FE_RESET
- FETCH_CLASS
- FETCH_CONSTANT
- FETCH_DIM_FUNC_ARG
- FETCH_DIM_IS
- FETCH_DIM_R
- FETCH_DIM_RW
- FETCH_DIM_TMP_VAR
- FETCH_DIM_UNSET
- FETCH_DIM_W
- FETCH_FUNC_ARG
- FETCH_IS
- FETCH_OBJ_FUNC_ARG
- FETCH_OBJ_IS
- FETCH_OBJ_R
- FETCH_OBJ_RW
- FETCH_OBJ_UNSET
- FETCH_OBJ_W
- FETCH_R
- FETCH_RW
- FETCH_UNSET
- FETCH_W
- FREE
- GOTO
- HANDLE_EXCEPTION
- INCLUDE_OR_EVAL
- INIT_ARRAY
- INIT_FCALL_BY_NAME
- INIT_METHOD_CALL
- INIT_NS_FCALL_BY_NAME
- INIT_STATIC_METHOD_CALL
- INIT_STRING
- INSTANCEOF
- IS_EQUAL
- IS_IDENTICAL
- IS_NOT_EQUAL
- IS_NOT_IDENTICAL
- IS_SMALLER
- IS_SMALLER_OR_EQUAL
- ISSET_ISEMPTY_DIM_OBJ
- ISSET_ISEMPTY_PROP_OBJ
- ISSET_ISEMPTY_VAR
- JMP
- JMPNZ
- JMPNZ_EX
- JMPZ
- JMPZ_EX
- JMPZNZ
- MOD
- MUL
- NEW
- NOP
- POST_DEC
- POST_DEC_OBJ
- POST_INC
- POST_INC_OBJ
- PRE_DEC
- PRE_DEC_OBJ
- PRE_INC
- PRE_INC_OBJ
- QM_ASSIGN
- RAISE_ABSTRACT_ERROR
- RECV
- RECV_INIT
- RETURN
- RETURN_BY_REF
- SEND_REF
- SEND_VAL
- SEND_VAR
- SEND_VAR_NO_REF
- SL
- SR
- SUB
- SWITCH_FREE
- THROW
- TICKS
- UNSET_DIM
- UNSET_OBJ
- UNSET_VAR
- USER_OPCODE
- VERIFY_ABSTRACT_CLASS
- ZEND_DECLARE_LAMBDA_FUNCTION
- ZEND_JMP_SET
Коментарии
Might be helpful:
I had to create and "INSERT INTO" on every 50th row:
<?php
$lineBreak = 50;
$tableName = 'user';
$tableFields = 'id, name, password';
?>
in the loop:
<?php
if ($counter === 0 || $counter % $lineBreak === 0) {
echo "INSERT INTO $tableName ($tableFields) VALUES (";
} else {
echo ' (';
}
// add values comma-delimited
if ($counter === 0 || $counter % $lineBreak === 0) {
$insertStmt .= ');';
} else {
$insertStmt .= '),';
}
?>
(in my case I had to check if $no % $o === 0)
To determine odd or even it's faster and more efficient to use the bitwise & operator:
$a = 3;
if ($a & 1) {
echo 'odd';
} else {
echo 'even';
}
// returns 'odd'
A function to handle integers of any length, including negatives. Returns remainder but also calculates division in the process (could be useful in some cases).
<?php
function remainder($dividend, $divisor) {
if ($dividend == 0 || $divisor == 0) return 0;
$dividend .= '';
$remainder = 0;
$division = '';
// negative case
while ($dividend < 0) {
$dividend += $divisor;
if ($dividend >= 0) return $dividend;
}
// positive case
while (($remainder.$dividend)*1 > $divisor) {
// get remainder big enough to divide
while ($remainder*1 < $divisor) {
$remainder .= $dividend[0];
$remainder *= 1;
$dividend = substr($dividend, 1);
}
// get highest multiplicator for remainder
$mult = floor($remainder / $divisor);
// add multiplicator to division
$division .= $mult.'';
// subtract from remainder
$remainder -= $mult*$divisor;
}
// add remaining zeros if any, to division
if (strlen($dividend) > 0 && $dividend*1 == 0) {
$division .= $dividend;
}
return $remainder;
}