The problem of exchanging two integer variables (without using the third) is one of the classic programmer riddles.
How to do this in PHP using the minimum number of characters?
Victory criteria - the minimum number of characters. All other things being equal, the answer published earlier wins. Summing up after 24 hours.
Please indicate in the response the number of characters, so that it is easier to identify the winner.
function getAnswers(questionId, answer_filter, page) { return jQuery.ajax({ url: '//api.stackexchange.com/2.2/questions/' + questionId + '/answers?page=' + page + '&pagesize=100&order=desc&sort=activity&site=ru.stackoverflow&filter=' + answer_filter, method: "get", dataType: "jsonp", crossDomain: true }).then(function(data) { if (data.has_more) { return getAnswers(questionId, answer_filter, page + 1).then(function(d) { return data.items.concat(d.items); }) } return data.items; }); } function getAuthorName(e) { return e.owner.display_name } function process(items) { return items.map(function(item) { var matched = item.body.match(/(\d+)[^\d]*?<\/h/); if (matched) { return { count: +matched[1], link: item.share_link, author: getAuthorName(item) }; } else { return { count: 'N/A', link: item.share_link, author: getAuthorName(item) } } }); } function sort(items) { return items.sort(function(a, b) { if (a.count == 'N/A') return 1; if (b.count == 'N/A') return -1; return a.count - b.count; }) } function fillTemplate(sortedItems) { $('#leadership').append(sortedItems.map(function(item, index) { return $('<tr>').append($('<td>').html(index + 1)) .append($('<td>').html(item.author)) .append($('<td>').html(item.count)) .append($('<td>').append($('<a>').attr('href', item.link).text('Link'))); })); return sortedItems; } var QUESTION_ID = 540286, ANSWER_FILTER = "!4*SyY(4Kifo3Mz*lT", startPage = 1; getAnswers(QUESTION_ID, ANSWER_FILTER, startPage) .then(process) .then(sort) .then(fillTemplate); #leadership { border-collapse: collapse; } #leadership td, #leadership th { padding: 5px; } #leadership th, td:nth-child(3) { text-align: center; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <h1>Таблица лидеров</h1> <table id="leadership"> <tr> <th></th> <th>Автор</th> <th>Количество символов</th> <th></th> </tr> </table> Comment on the reason for choosing the winner:
The leading answer @PashaPash (0 characters) does not actually change the variables, so it does not participate in the competition.
The answer from @Naumov (10 characters), instead of exchanging variables, simply assigns them new values. Well, its length is not constant, but depends on the values of variables. I will not consider this answer as part of the competition program.
PHP = кака-код. It's time to change this by asking good, interesting questions. Golf is one of the ways. - Dmitriy Simushev